diff options
| -rw-r--r-- | test/integration/container_test.go | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/test/integration/container_test.go b/test/integration/container_test.go index becad4a..dcea018 100644 --- a/test/integration/container_test.go +++ b/test/integration/container_test.go @@ -16,18 +16,17 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/network" "github.com/testcontainers/testcontainers-go/wait" "github.com/xlgmokha/x/pkg/env" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" ) -type StdoutLogConsumer struct { +type TestLogConsumer struct { t *testing.T } -func (lc *StdoutLogConsumer) Accept(l testcontainers.Log) { +func (lc *TestLogConsumer) Accept(l testcontainers.Log) { lc.t.Logf("%s", l.Content) } @@ -35,25 +34,16 @@ func TestContainer(t *testing.T) { srv := oidc.NewTestServer(t) defer srv.Close() - image := env.Fetch("IMAGE_TAG", "sparkled:invalid") - require.NotEmpty(t, image) - ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() - nw, err := network.New(ctx) - require.NoError(t, err) - defer func() { - require.NoError(t, nw.Remove(ctx)) - }() address, err := url.Parse(srv.MockOIDC.Addr()) require.NoError(t, err) t.Logf("mockoidc: %v %v\n", address.String(), srv.Issuer()) container, err := testcontainers.Run( ctx, - image, - network.WithNetwork([]string{"host"}, nw), + env.Fetch("IMAGE_TAG", "sparkled:invalid"), testcontainers.WithEnv(map[string]string{ "APP_ENV": "test", "BIND_ADDR": ":8080", @@ -66,15 +56,12 @@ func TestContainer(t *testing.T) { }), testcontainers.WithHostPortAccess(x.Must(strconv.Atoi(address.Port()))), testcontainers.WithExposedPorts("8080/tcp", "9901/tcp", "10000/tcp"), - testcontainers.WithLogConsumers(&StdoutLogConsumer{t: t}), + testcontainers.WithLogConsumers(&TestLogConsumer{t: t}), testcontainers.WithWaitStrategy(wait.ForLog("Listening on").WithStartupTimeout(time.Second*5)), ) require.NoError(t, err) - defer func() { - require.NoError(t, testcontainers.TerminateContainer(container)) - testcontainers.CleanupNetwork(t, nw) - }() + defer testcontainers.TerminateContainer(container) oidcProviderEndpoint := address.String() sparkleEndpoint, err := container.PortEndpoint(ctx, "8080", "http") @@ -117,10 +104,8 @@ func TestContainer(t *testing.T) { })) page := x.Must(browser.NewPage()) - defer func() { - x.Check(browser.Close()) - x.Check(pw.Stop()) - }() + defer browser.Close() + defer pw.Stop() t.Run("initiates an OIDC login", func(t *testing.T) { require.NoError(t, page.Context().ClearCookies()) |
