Merged in feature/postprocessing (pull request #114)
Feature/postprocessing * tests * passtest * fixshorttests * mosttests * improvingbasedockerfile * testspeeds * testing * host * canparallel * clean * passfullsuite * singlepagemax * test * findfeatures * findstables * tbls * tablestoo * tablestoo * lateraltests * tableloc * cleanup * inlinetable * childids * cleanup * tests
This commit is contained in:
+23
-53
@@ -3,12 +3,12 @@ package test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
db "queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/database"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -17,24 +17,26 @@ import (
|
||||
)
|
||||
|
||||
type CreateDatabaseConfig struct {
|
||||
Network *testcontainers.DockerNetwork
|
||||
RunMigrations bool
|
||||
}
|
||||
|
||||
func CreateDB(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvider, dcfg *CreateDatabaseConfig) (testcontainers.Container, func()) {
|
||||
alias := "postgres"
|
||||
const (
|
||||
dbAlias = "postgres"
|
||||
dbPort = 5432
|
||||
)
|
||||
|
||||
port, err := nat.NewPort("tcp", "5432")
|
||||
func CreateDB(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvider, network string, dcfg *CreateDatabaseConfig) testcontainers.Container {
|
||||
port, err := nat.NewPort("tcp", strconv.Itoa(dbPort))
|
||||
require.NoError(t, err)
|
||||
|
||||
name := "queryorchestration"
|
||||
name := NormaliseAlias(fmt.Sprintf("queryorchestration_%s", t.Name()))
|
||||
pass := "pass"
|
||||
user := "postgres"
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "postgres:17.2-alpine3.21",
|
||||
Name: "postgres_test_queryorchestration",
|
||||
Env: map[string]string{
|
||||
"POSTGRES_DB": name,
|
||||
"POSTGRES_USER": user,
|
||||
"POSTGRES_PASSWORD": pass,
|
||||
},
|
||||
@@ -44,24 +46,22 @@ func CreateDB(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvide
|
||||
wait.ForListeningPort(port),
|
||||
wait.ForLog("database system is ready to accept connections"),
|
||||
wait.ForSQL(port, "postgres", func(host string, port nat.Port) string {
|
||||
return fmt.Sprintf("postgres://%s:%s@localhost:%s/%s?sslmode=disable",
|
||||
user, pass, port.Port(), name)
|
||||
return fmt.Sprintf("postgres://%s:%s@%s:%d/postgres?sslmode=disable",
|
||||
user, pass, host, port.Int())
|
||||
}).
|
||||
WithStartupTimeout(25*time.Second).
|
||||
WithPollInterval(10*time.Second),
|
||||
),
|
||||
}
|
||||
|
||||
if dcfg.Network != nil {
|
||||
req.Networks = []string{dcfg.Network.Name}
|
||||
req.NetworkAliases = map[string][]string{
|
||||
dcfg.Network.Name: {alias},
|
||||
}
|
||||
Networks: []string{network},
|
||||
NetworkAliases: map[string][]string{
|
||||
network: {dbAlias},
|
||||
},
|
||||
}
|
||||
|
||||
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: req,
|
||||
Started: true,
|
||||
Reuse: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -70,28 +70,12 @@ func CreateDB(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvide
|
||||
mappedPort, err := container.MappedPort(ctx, port)
|
||||
require.NoError(t, err)
|
||||
|
||||
dbcfg := &database.DBConfig{
|
||||
DBName: name,
|
||||
DBSecret: pass,
|
||||
DBUser: user,
|
||||
DBPort: mappedPort.Int(),
|
||||
DBHost: host,
|
||||
DBNoSSL: true,
|
||||
}
|
||||
|
||||
t.Setenv("PGUSER", dbcfg.DBUser)
|
||||
t.Setenv("PGPASSWORD", dbcfg.DBSecret)
|
||||
t.Setenv("PGDATABASE", dbcfg.DBName)
|
||||
t.Setenv("DB_NOSSL", fmt.Sprintf("%v", dbcfg.DBNoSSL))
|
||||
t.Setenv("PGHOST", dbcfg.DBHost)
|
||||
t.Setenv("PGPORT", fmt.Sprint(dbcfg.DBPort))
|
||||
|
||||
cfg.SetDBUser(dbcfg.DBUser)
|
||||
cfg.SetDBSecret(dbcfg.DBSecret)
|
||||
cfg.SetDBName(dbcfg.DBName)
|
||||
cfg.SetDBNoSSL(dbcfg.DBNoSSL)
|
||||
cfg.SetDBHost(dbcfg.DBHost)
|
||||
cfg.SetDBPort(dbcfg.DBPort)
|
||||
cfg.SetDBUser(user)
|
||||
cfg.SetDBSecret(pass)
|
||||
cfg.SetDBName(name)
|
||||
cfg.SetDBNoSSL(true)
|
||||
cfg.SetDBHost(host)
|
||||
cfg.SetDBPort(mappedPort.Int())
|
||||
|
||||
if dcfg.RunMigrations {
|
||||
err := db.RunMigrations(ctx, cfg)
|
||||
@@ -101,19 +85,5 @@ func CreateDB(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvide
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if dcfg.Network != nil {
|
||||
dbcfg.DBHost = alias
|
||||
dbcfg.DBPort = port.Int()
|
||||
cfg.SetDBUser(dbcfg.DBUser)
|
||||
cfg.SetDBSecret(dbcfg.DBSecret)
|
||||
cfg.SetDBName(dbcfg.DBName)
|
||||
cfg.SetDBNoSSL(dbcfg.DBNoSSL)
|
||||
cfg.SetDBHost(dbcfg.DBHost)
|
||||
cfg.SetDBPort(dbcfg.DBPort)
|
||||
}
|
||||
|
||||
return container, func() {
|
||||
err := container.Terminate(ctx)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
return container
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user