Merged in feature/testingopts (pull request #129)

Testing Options and Clean Up

* bitsandbobs

* lint

* healthchecks

* imgintests

* singlegenerate

* testclean

* network

* networkclean

* cmds
This commit is contained in:
Michael McGuinness
2025-05-03 01:16:53 +00:00
parent 15fa3b49a5
commit dd2eebf13a
73 changed files with 4657 additions and 234 deletions
+49 -1
View File
@@ -5,12 +5,16 @@ import (
"context"
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
"sync"
"testing"
"queryorchestration/internal/serviceconfig"
"github.com/docker/go-connections/nat"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
@@ -31,6 +35,48 @@ type containerConfig struct {
MockHTTP string
}
const (
imageTag = "queryorchestration:latest"
)
var (
imageBuild sync.Once
)
func buildImage(t testing.TB) {
imageBuild.Do(func() {
dockerContextPath, err := os.Getwd()
require.NoError(t, err, "Failed to get current directory")
dockerfilePath := "build/Dockerfile"
for {
candidatePath := filepath.Join(dockerContextPath, dockerfilePath)
t.Logf("Checking for Dockerfile at: %s", dockerContextPath)
if _, err := os.Stat(candidatePath); err == nil {
dockerfilePath = candidatePath
t.Logf("Found Dockerfile at: %s", candidatePath)
break
}
dockerContextPath = filepath.Join(dockerContextPath, "..")
}
dockerBuildCmd := shell.Command{
Command: "docker",
Args: []string{
"build",
"--file", dockerfilePath,
"--tag", imageTag,
dockerContextPath,
},
}
err = shell.RunCommandE(t, dockerBuildCmd)
require.NoError(t, err)
})
}
func createContainer(t testing.TB, ctx context.Context, network string, cfg *containerConfig) (testcontainers.Container, func()) {
env := map[string]string{
"PGUSER": cfg.Cfg.GetDBUser(),
@@ -65,8 +111,10 @@ func createContainer(t testing.TB, ctx context.Context, network string, cfg *con
env[string(GetRunnerEnvFromName(e))] = GetQueueURL(t, cfg.Cfg, e)
}
buildImage(t)
req := testcontainers.ContainerRequest{
Image: "queryorchestration:latest",
Image: imageTag,
Env: env,
WaitingFor: wait.ForLog(cfg.WaitForMsg),
Entrypoint: []string{fmt.Sprintf("./%s", cfg.Name)},