2023-12-20 07:03:03 +00:00
|
|
|
package adapter_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2024-01-14 10:04:17 +00:00
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/bun/buntest"
|
2023-12-20 07:03:03 +00:00
|
|
|
"github.com/ory/dockertest/v3"
|
|
|
|
)
|
|
|
|
|
2024-01-14 10:04:17 +00:00
|
|
|
var postgres *buntest.Postgres
|
2023-12-20 07:03:03 +00:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(testMainWrapper(m))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMainWrapper(m *testing.M) int {
|
|
|
|
// https://github.com/golang/go/blob/7cfa7d69259590319524c3715df4a39b39924bc3/src/testing/testing.go#L224
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if testing.Short() {
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
pool, err := dockertest.NewPool("")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("couldn't construct dockertest.Pool:", err)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2024-01-14 10:04:17 +00:00
|
|
|
postgres, err = buntest.NewPostgres(pool)
|
2023-12-20 07:03:03 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println("couldn't construct adaptertest.Postgres:", err)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
_ = postgres.Close()
|
|
|
|
}()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|