import (
"testing"
_ "github.com/lib/pq"
"os"
"github.com/ory/dockertest"
"log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"fmt"
)
func TestMain(m *testing.M) {
var db *gorm.DB
var err error
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Could not connect to docker: %s", err)
}
resource, err := pool.Run("postgres", "9.6.5-alpine", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=test"})
if err != nil {
log.Fatalf("Could not start resource: %s", err)
}
if err = pool.Retry(func() error {
var err error
hostPort := resource.GetHostPort("5432/tcp")
dbConnStr := fmt.Sprintf("postgres://postgres:secret@%s/test?sslmode=disable", hostPort)
db, err = gorm.Open("postgres", dbConnStr)
if err != nil {
panic(fmt.Sprintf("Failed to connect database: %v", err))
}
return db.DB().Ping()
}); err != nil {
log.Fatalf("Could not connect to docker: %s", err)
}
code := m.Run()
if err = pool.Purge(resource); err != nil {
log.Fatalf("Could not purge resource %s", err)
}
os.Exit(code)
}
func TestGet(t *testing.T) {
t.Fail()
}