func TestConnection(t *testing.T) { dbM, err := saver.NewDbManager("root:mypassa@tcp(127.0.0.1:3306)/greader") defer dbM.Close() if err == nil { t.Error("Bad Error Handling for bad credentials") } dbM, err = saver.NewDbManager("root:mypass@tcp(127.0.0.1:3306)/greader") defer dbM.Close() dbM.Ping() dbM.Close() if err != nil { t.Error(err) dbM.Close() } }
// DbManager adds objectSQL on the fly func TestAddStruct(t *testing.T) { obj := testSQL{1, "tatatata", "yoyo", 25, 42, nil} dbM, err := saver.NewDbManager("root:mypass@tcp(127.0.0.1:3306)/greader") defer dbM.Close() err = dbM.Save(&obj) if err != nil { t.Error(err) } }
/* * Create Database and tables associated to the objects */ func TestCreateDatabase(t *testing.T) { obj := testSQL{} slave := copain{} var err error db, err = saver.NewDbManager("root:mypass@tcp(127.0.0.1:3306)/greader") if err != nil { t.Error(err) } err = db.CreateTable(&obj) if err != nil { t.Error(err) } err = db.CreateTable(&slave) if err != nil { t.Error(err) } }