//go:build integration // +build integration package test import ( "context" "net/http" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" "github.com/xlgmokha/x/pkg/env" ) func TestContainer(t *testing.T) { image := env.Fetch("IMAGE_TAG", "sparkled:main") require.NotEmpty(t, image) ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ Image: image, ExposedPorts: []string{"80/tcp"}, WaitingFor: wait.ForLog("Listening on"), }, Started: true, }) require.NoError(t, err) defer func() { require.NoError(t, container.Terminate(context.Background())) testcontainers.CleanupContainer(t, container) }() endpoint, err := container.Endpoint(ctx, "") require.NoError(t, err) paths := []string{ "/health", "/favicon.ico", } for _, path := range paths { t.Run(path, func(t *testing.T) { url := "http://" + endpoint + path client := &http.Client{Timeout: 5 * time.Second} request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) response, err := client.Do(request) require.NoError(t, err) assert.Equal(t, http.StatusOK, response.StatusCode) }) } }