Exemplo n.º 1
0
// Test a Mongo database
func TestMongo(t *testing.T) {
	session, err := mgo.DialWithTimeout("127.0.0.1:27017", time.Second)
	if err != nil {
		t.Skip("No database: ", err)
	}
	coll := session.DB("testdb").C("password-test")
	_ = coll.DropCollection()

	// Set timeout, otherwise travis sometimes gets timeout.
	session.SetSocketTimeout(time.Minute)
	session.SetSyncTimeout(time.Minute)

	db := New(session, "testdb", "password-test")
	err = drivers.TestImport(db)
	if err != nil {
		t.Fatal(err)
	}

	// Be sure data is flushed, probably not needed, but we like to be sure
	err = session.Fsync(false)
	if err != nil {
		t.Log("Fsync returned", err, "(ignoring)")
	}

	err = drivers.TestData(db)
	if err != nil {
		t.Fatal(err)
	}

	err = coll.DropCollection()
	if err != nil {
		t.Log("Drop returned", err, "(ignoring)")
	}
	session.Close()
}
Exemplo n.º 2
0
// Test a Cassandra database
func TestCassandra(t *testing.T) {
	cluster := gocql.NewCluster("127.0.0.1")
	cluster.Keyspace = "testkeyspace"
	cluster.Consistency = gocql.Quorum
	session, err := cluster.CreateSession()
	if err != nil {
		t.Fatal("createsession", err)
	}
	defer session.Close()

	err = session.Query(`CREATE KEYSPACE IF NOT EXISTS testkeyspace with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };`).Exec()
	if err != nil {
		t.Fatal("createkeyspace", err)
	}
	_ = session.Query(`DROP TABLE IF EXISTS passwords`).Exec()

	err = session.Query(`CREATE TABLE testkeyspace.passwords(password text, PRIMARY KEY(password));`).Exec()
	if err != nil {
		t.Fatal("createkeyspace", err)
	}

	defer session.Query(`DROP TABLE IF EXISTS passwords`).Exec()

	db := New(session, "passwords")
	err = drivers.TestImport(db)
	if err != nil {
		t.Fatal(err)
	}

	err = drivers.TestData(db)
	if err != nil {
		t.Fatal(err)
	}
}