Example #1
0
func TestConnectAndQuery(t *testing.T) {

	mysqlCtnr, mysqlUrl = prefab.StartMysqlContainer()

	defer func() {
		if r := recover(); r != nil {
			t.Error("Should not have panicked: ", r)
		}
	}()

	prefab.WaitForMysql(mysqlUrl, 30*time.Second)

	Init(func(c *Config) {
		c.ConnectString = mysqlUrl
		t.Log("[" + c.ConnectString + "]")
	})

	if DB == nil {
		t.Error("DB was nil, not good.")
	}

	_ = DB.MustExec("select 1")

	prefab.Remove(mysqlCtnr)

}
Example #2
0
func TestConnectAndQuery(t *testing.T) {
	var err error

	psqlCntr, psqlUrl := prefab.StartPostgresContainer()

	defer func() {
		if r := recover(); r != nil {
			t.Error("Should not have panicked: ", r)
		}
	}()

	prefab.WaitForPostgres(psqlUrl, 10*time.Second)
	Init(func(c *Config) {
		c.ConnectString = psqlUrl + "?sslmode=disable"
	})

	if DB == nil {
		t.Error("DB was nil, not good.")
	}

	_, err = DB.SQL("select $1", 1).Exec()
	if err != nil {
		t.Error("Failed to do select: ", err.Error())
	}

	prefab.Remove(psqlCntr)

}
Example #3
0
func TestMain(m *testing.M) {
	// your func
	setup()

	retCode := m.Run()

	// call with result of m.Run()
	prefab.Remove(natsContainer)
	os.Exit(retCode)
}
Example #4
0
func (this *TestEnvironment) Cleanup() {
	wg := sync.WaitGroup{}

	wg.Add(len(this.ids))
	for _, id := range this.ids {
		go func() {
			prefab.Remove(id)
			wg.Done()
		}()
		time.Sleep(50 * time.Millisecond)
	}
	wg.Wait()
}