| 31 | var stack tc.ComposeStack |
| 32 | |
| 33 | func TestMain(m *testing.M) { |
| 34 | level := slog.LevelDebug |
| 35 | logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ |
| 36 | Level: level, |
| 37 | })) |
| 38 | slog.SetDefault(logger) |
| 39 | |
| 40 | // Start the h2o docker container |
| 41 | identifier := tc.StackIdentifier("h2o_test") |
| 42 | composeFile := fmt.Sprintf("%s/docker-compose.yml", testutils.RootDir()) |
| 43 | compose, err := tc.NewDockerComposeWith(tc.WithStackFiles(composeFile), identifier) |
| 44 | if err != nil { |
| 45 | log.Fatalf("error in NewDockerComposeAPIWith: %v", err) |
| 46 | } |
| 47 | |
| 48 | defer func() { |
| 49 | if err := compose.Down( |
| 50 | context.Background(), |
| 51 | tc.RemoveOrphans(true), |
| 52 | tc.RemoveImagesLocal, |
| 53 | ); err != nil { |
| 54 | log.Fatalf("error in compose.Down: %v", err) |
| 55 | } |
| 56 | }() |
| 57 | |
| 58 | ctx, cancel := context.WithCancel(context.Background()) |
| 59 | defer cancel() |
| 60 | |
| 61 | stack = compose.WaitForService(h2oServiceName, |
| 62 | // The h2o conf provides a /status endpoint listening on |
| 63 | // non-TLS port 8081 |
| 64 | wait. |
| 65 | NewHTTPStrategy("/status"). |
| 66 | WithPort("8081/tcp"). |
| 67 | WithStartupTimeout(10*time.Second), |
| 68 | ) |
| 69 | |
| 70 | if err := stack.Up(ctx, tc.Wait(true), tc.RunServices("h2o")); err != nil { |
| 71 | log.Fatalf("error in compose.Up(): %v", err) |
| 72 | } |
| 73 | |
| 74 | container, err := stack.ServiceContainer(ctx, h2oServiceName) |
| 75 | if err != nil { |
| 76 | log.Fatalf("error in stack.ServiceContainer: %v", err) |
| 77 | } |
| 78 | |
| 79 | logger.Info("compose up", "services", stack.Services(), "container", container) |
| 80 | |
| 81 | // Kind of awkward network info parsing here. |
| 82 | // We need the container's gateway IP because that _should_ be the address the host can ListenUDP on where the container can access it. |
| 83 | containerIPs, err := container.ContainerIPs(ctx) |
| 84 | if err != nil { |
| 85 | log.Fatalf("error in container.ContainerIPs: %v", err) |
| 86 | } |
| 87 | |
| 88 | containerIP := containerIPs[0] |
| 89 | containerIPSplit := strings.Split(containerIP, ".") |
| 90 | containerNet := strings.Join(containerIPSplit[:len(containerIPSplit)-1], ".") |