Пример #1
0
// TestImport will import about 1500 entries into your
// database. It will test "Add" and "AddMultiple" (if available).
// If any error is returned the test failed.
func TestImport(db password.DbWriter) error {
	buf, err := testdata.Asset("testdata.txt.gz")
	if err != nil {
		return err
	}
	in, err := tokenizer.NewGzLine(bytes.NewBuffer(buf))
	if err != nil {
		return err
	}
	writer, ok := db.(password.DbWriter)
	if !ok {
		return fmt.Errorf("%T is not a DbWriter", db)
	}
	err = password.Import(in, writer, nil)
	if err != nil {
		return err
	}
	// Test Add once separately
	err = writer.Add(single_val)
	if err != nil {
		return err
	}
	// .. and test that it is ok to write it again.
	err = writer.Add(single_val)
	if err != nil {
		return err
	}
	return nil
}
Пример #2
0
func TestImport(t *testing.T) {
	buf, err := testdata.Asset("testdata.txt.gz")
	if err != nil {
		t.Fatal(err)
	}
	mem := testdb.NewMemDB()
	in, err := tokenizer.NewGzLine(bytes.NewBuffer(buf))
	if err != nil {
		t.Fatal(err)
	}
	err = Import(in, mem, nil)
	if err != nil {
		t.Fatal(err)
	}
}
Пример #3
0
func TestInDBBulk(t *testing.T) {
	buf, err := testdata.Asset("testdata.txt.gz")
	if err != nil {
		t.Fatal(err)
	}
	mem := testdb.NewMemDBBulk()
	in, err := tokenizer.NewGzLine(bytes.NewBuffer(buf))
	if err != nil {
		t.Fatal(err)
	}
	err = Import(in, mem, nil)
	for p := range testdata.TestSet {
		if SanitizeOK(p, nil) != nil {
			continue
		}
		has, err := inDB(p, mem, nil)
		if err != nil {
			t.Fatal(err)
		}
		if !has {
			t.Fatalf("db should have: %s", p)
		}
		err = Check(p, mem, nil)
		if err != ErrPasswordInDB {
			t.Fatal("check failed on:", p, err)
		}
	}
	for p := range testdata.NotInSet {
		if SanitizeOK(p, nil) != nil {
			continue
		}
		has, err := inDB(p, mem, nil)
		if err != nil {
			t.Fatal(err)
		}
		if has {
			t.Fatalf("db should not have: %s", p)
		}
		err = Check(p, mem, nil)
		if err != nil {
			t.Fatal("check failed on:", p, err)
		}
	}
}
Пример #4
0
func TestImportBulk(t *testing.T) {
	buf, err := testdata.Asset("testdata.txt.gz")
	if err != nil {
		t.Fatal(err)
	}
	mem := testdb.NewMemDBBulk()
	in, err := tokenizer.NewGzLine(bytes.NewBuffer(buf))
	if err != nil {
		t.Fatal(err)
	}
	err = Import(in, mem, nil)
	if err != nil {
		t.Fatal(err)
	}
	// Test everything is kept open.
	err = Import(in, mem, nil)
	if err != nil {
		t.Fatal(err)
	}
}