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
|
package test
import (
"context"
"net/url"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"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 {
t.Logf("mockoidc: %v %v\n", testcontainers.HostInternal, envVars)
issuer := envVars["OIDC_ISSUER"]
u, err := url.Parse(issuer)
require.NoError(t, err)
port, err := strconv.Atoi(u.Port())
require.NoError(t, err)
container, err := testcontainers.Run(
ctx,
env.Fetch("IMAGE_TAG", "sparkled:invalid"),
testcontainers.WithEnv(envVars),
testcontainers.WithExposedPorts("8080/tcp", "9901/tcp", "10000/tcp"),
testcontainers.WithHostPortAccess(port),
testcontainers.WithLogConsumers(&LogConsumer{t: t}),
testcontainers.WithWaitStrategy(wait.ForLog("Listening on").WithStartupTimeout(10*time.Second)),
)
require.NoError(t, err)
return container
}
|