summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-14 13:45:14 -0600
committermo khan <mo@mokhan.ca>2025-04-14 13:45:14 -0600
commite735969caf8ad4714e8d22f0da70df6c6b350a06 (patch)
treed8ba4ba03a86df24e95580653c4db5d531fd13dc /test
parent9114ec7755fad2653d6093acd3839ec2dbe489a0 (diff)
test: add an integration test and run in CI
Diffstat (limited to 'test')
-rw-r--r--test/integration/container_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/integration/container_test.go b/test/integration/container_test.go
new file mode 100644
index 0000000..76e6a03
--- /dev/null
+++ b/test/integration/container_test.go
@@ -0,0 +1,53 @@
+//go:build integration
+// +build integration
+
+package test
+
+import (
+ "context"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+ "github.com/testcontainers/testcontainers-go"
+ "github.com/testcontainers/testcontainers-go/wait"
+ "github.com/xlgmokha/x/pkg/env"
+ "gotest.tools/v3/assert"
+)
+
+func TestContainer(t *testing.T) {
+ t.Run("GET /health", func(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)
+
+ path := "http://" + endpoint + "/health"
+ client := &http.Client{Timeout: 5 * time.Second}
+ request, err := http.NewRequestWithContext(ctx, http.MethodGet, path, nil)
+ response, err := client.Do(request)
+ require.NoError(t, err)
+ assert.Equal(t, http.StatusOK, response.StatusCode)
+ })
+}