-
Notifications
You must be signed in to change notification settings - Fork 23
/
main_test.go
53 lines (47 loc) · 1.19 KB
/
main_test.go
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
package main
import (
"context"
"fmt"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"testing"
)
func TestScenarios(t *testing.T) {
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "ghcr.io/jamesward/easyracer",
ExposedPorts: []string{"8080/tcp"},
WaitingFor: wait.ForHTTP("/").WithPort("8080"),
}
scenarioServer, containerErr := testcontainers.GenericContainer(
ctx,
testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
},
)
if containerErr != nil {
t.Error(containerErr)
}
defer func() {
if err := scenarioServer.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err.Error())
}
}()
baseURL, endpointErr := scenarioServer.Endpoint(ctx, "http")
if endpointErr != nil {
t.Error(endpointErr)
}
scenarioURL := func(scenario int) string {
return fmt.Sprintf("%s/%d", baseURL, scenario)
}
for idx, scenario := range scenarios {
name := fmt.Sprintf("scenario%d", idx+1)
t.Run(name, func(t *testing.T) {
got := scenario(scenarioURL)
if got != "right" {
t.Errorf(`%s = "%s"; want "right"`, name, got)
}
})
}
}