1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package test
import (
"context"
"net/http"
"path/filepath"
"testing"
xcontainer "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/log"
"github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/xlgmokha/x/pkg/env"
)
func NewContainer(t *testing.T, ctx context.Context, envVars map[string]string) *testcontainers.DockerContainer {
require.Equal(t, http.StatusOK, HttpGet(t, ctx, envVars["OIDC_ISSUER"]+"/.well-known/openid-configuration").StatusCode)
procfilePath, err := filepath.Abs("../../Procfile.test")
require.NoError(t, err)
container, err := testcontainers.Run(
ctx,
env.Fetch("IMAGE_TAG", "sparkled:invalid"),
testcontainers.WithEnv(envVars),
testcontainers.WithLogConsumers(&Logger{TB: t}),
testcontainers.WithLogger(log.TestLogger(t)),
testcontainers.WithMounts(testcontainers.BindMount(procfilePath, "/Procfile")),
testcontainers.WithWaitStrategy(
wait.ForHTTP("/").WithPort("10000"),
),
testcontainers.WithHostConfigModifier(func(cfg *xcontainer.HostConfig) {
cfg.NetworkMode = xcontainer.NetworkMode(network.NetworkHost)
}),
// testcontainers.WithExposedPorts("10000/tcp"),
// testcontainers.WithHostPortAccess(port),
)
require.NoError(t, err)
return container
}
func NewPgContainer(ctx context.Context, t *testing.T) *postgres.PostgresContainer {
container, err := postgres.Run(ctx, "postgres:17",
postgres.WithDatabase("sparkle_test"),
postgres.WithUsername("postgres"),
postgres.WithPassword("secret"),
testcontainers.WithLogConsumers(&Logger{TB: t}),
testcontainers.WithLogger(log.TestLogger(t)),
testcontainers.WithWaitStrategy(
wait.ForListeningPort("5432/tcp"),
),
)
require.NoError(t, err)
return container
}
|