예제 #1
0
// Test a MySQL database
func TestMySQL(t *testing.T) {
	db, err := sql.Open("mysql", "travis:@/testdb")
	if err != nil {
		t.Skip("MySQL connect error:", err)
	}
	err = db.Ping()
	if err != nil {
		t.Skip("MySQL ping error:", err)
	}

	drop := "DROP TABLE `testdb`.`test-table`;"
	create := "CREATE TABLE `testdb`.`test-table` (`Pass` VARCHAR(64) NOT NULL COMMENT '', PRIMARY KEY (`Pass`)  COMMENT '', UNIQUE INDEX `Pass_UNIQUE` (`Pass` ASC)  COMMENT '') DEFAULT CHARACTER SET = utf8;"

	_, _ = db.Exec(drop)
	_, err = db.Exec(create)
	if err != nil {
		t.Fatal(err)
	}

	d := NewMysql(db, "test-table", "Pass")
	err = drivers.TestDriver(d)
	if err != nil {
		t.Fatal(err)
	}
	_, err = db.Exec(drop)
	if err != nil {
		t.Log("DROP returned:", err)
	}
}
예제 #2
0
// Test a bloom database
func TestBloom(t *testing.T) {
	// create a bloom filter for 65536 items and 0.001 % wrong-positive ratio
	filter := bbloom.New(float64(1<<16), float64(0.00001))

	bloom, err := New(&filter)
	if err != nil {
		t.Fatal(err)
	}
	err = drivers.TestDriver(bloom)
	if err != nil {
		t.Fatal(err)
	}
}
예제 #3
0
// Example of using a MySQL database.
//
// This assumes "test-table" has been created in "testdb".
// It could have been created like this:
//
//	CREATE TABLE `testdb`.`test-table` (
//    `Pass` VARCHAR(64) NOT NULL,
//    PRIMARY KEY (`Pass`),
//    UNIQUE INDEX `Pass_UNIQUE` (`Pass` ASC)
//  ) DEFAULT CHARACTER SET = utf8;
func ExampleNewMysql() {
	db, err := sql.Open("mysql", "travis:@/testdb")
	if err != nil {
		panic("MySQL connect error " + err.Error())
	}

	d := NewMysql(db, "test-table", "Pass")

	// Test it
	err = drivers.TestDriver(d)
	if err != nil {
		panic(err)
	}
}
예제 #4
0
// Example of using a Postgres database
//
// Uses 'pwtesttable' in the 'testschema' schema,
// and reads/adds to the "pass" column.
//
// Table can be created like this:
//  `CREATE TABLE ` + table + ` ("`+ column +`" VARCHAR(64) PRIMARY KEY);`
//
// For Postgres to ignore duplicate inserts, you can use a rule
// like this:
//
//  `CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
//      ON INSERT TO ` + table + `
//      WHERE (EXISTS (
//          SELECT 1
//          FROM ` + table + `
//          WHERE ` + table + `.` + column + ` = NEW.` + column + `
//      )
//  ) DO INSTEAD NOTHING;`
func ExampleNewPostgresql() {
	db, err := sql.Open("postgres", "user=postgres dbname=postgres sslmode=disable")
	if err != nil {
		panic("Postgres connect error " + err.Error())
	}
	table := "testschema.pwtesttable"

	d := NewPostgresql(db, table, "pass")

	// Test it
	err = drivers.TestDriver(d)
	if err != nil {
		panic(err)
	}
}
예제 #5
0
// Test a Postgres database
// To run locally, use the "-pgpass" password to set the postgres user password.
func TestPostgres(t *testing.T) {
	db, err := sql.Open("postgres", "user=postgres dbname=postgres sslmode=disable password="******"Postgres connect error:", err)
	}
	err = db.Ping()
	if err != nil {
		t.Skip("Postgres ping error:", err)
	}

	table := "testschema.pwtesttable"
	drop := `DROP TABLE ` + table + `;`
	schema := `CREATE SCHEMA testschema AUTHORIZATION postgres`
	create := `CREATE TABLE ` + table + ` ("pass" VARCHAR(64) PRIMARY KEY);`
	ignore_rule := `
        CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
            ON INSERT TO ` + table + `
            WHERE (EXISTS ( 
                SELECT 1
                FROM ` + table + `
                WHERE ` + table + `.pass = NEW.pass
            ) ) DO INSTEAD NOTHING;`

	_, _ = db.Exec(drop)
	_, err = db.Exec(schema)
	if err != nil {
		t.Log("warning:", err)
	}
	_, err = db.Exec(create)
	if err != nil {
		t.Fatal(err)
	}
	_, err = db.Exec(ignore_rule)
	if err != nil {
		t.Fatal(err)
	}

	d := NewPostgresql(db, table, "pass")

	err = drivers.TestDriver(d)
	if err != nil {
		t.Fatal(err)
	}
	_, err = db.Exec(drop)
	if err != nil {
		t.Log("DROP returned:", err)
	}
}
예제 #6
0
// Test a bolt database
func TestBolt(t *testing.T) {
	db, err := bolt.Open(tempfile(), 0666, nil)
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(db.Path())
	defer db.Close()

	bolt, err := New(db, "commonpwd")
	if err != nil {
		t.Fatal(err)
	}
	err = drivers.TestDriver(bolt)
	if err != nil {
		t.Fatal(err)
	}
}
예제 #7
0
// Test a MemDBBulk database
func TestMemDBBulk(t *testing.T) {
	err := drivers.TestDriver(NewMemDBBulk())
	if err != nil {
		t.Fatal(err)
	}
}