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
+1 -1
View File
@@ -13,7 +13,7 @@ import (
func TestRunMigrations(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := t.Context()
cfg := &serviceconfig.BaseConfig{}
+1 -1
View File
@@ -15,7 +15,7 @@ import (
func TestClean(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -15,7 +15,7 @@ import (
func TestClient(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -17,7 +17,7 @@ import (
func TestCollector(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -15,7 +15,7 @@ import (
func TestDocument(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+4 -4
View File
@@ -16,7 +16,7 @@ import (
func TestQueries(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -226,7 +226,7 @@ func TestQueries(t *testing.T) {
func TestQueryDependencyTree(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -445,7 +445,7 @@ func TestQueryDependencyTree(t *testing.T) {
func TestQueriesList(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -501,7 +501,7 @@ func TestQueriesList(t *testing.T) {
func TestListQueryClients(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+3 -3
View File
@@ -18,7 +18,7 @@ import (
func TestResults(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -157,7 +157,7 @@ func TestResults(t *testing.T) {
func TestResultValues(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -371,7 +371,7 @@ func TestResultValues(t *testing.T) {
func TestUnsyncedNoDepsQueries(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+2 -2
View File
@@ -18,7 +18,7 @@ import (
func TestListClientDocumentIDs(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -168,7 +168,7 @@ func createClientWithCollector(t testing.TB, ctx context.Context, queries *repos
func TestClientSync(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
t.Run("document fail clean", func(t *testing.T) {
+3 -3
View File
@@ -18,7 +18,7 @@ import (
func TestTextExtraction(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -126,7 +126,7 @@ func TestTextExtraction(t *testing.T) {
func TestTextTextractPart(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -256,7 +256,7 @@ func TestTextTextractPart(t *testing.T) {
func TestTextOutPart(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -22,7 +22,7 @@ import (
func TestNewAPI(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -24,7 +24,7 @@ type TestConfig struct {
func TestNewRunner(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
cfg := &TestConfig{}
+1 -1
View File
@@ -16,7 +16,7 @@ import (
func TestNewServer(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -16,7 +16,7 @@ import (
func TestSetDBPool(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -88,7 +88,7 @@ func TestSetStoreClientAndPingByName(t *testing.T) {
func TestCalculateAndCompareETag(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -12,7 +12,7 @@ import (
func TestCreateAPI(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := t.Context()
+1 -1
View File
@@ -18,7 +18,7 @@ type TestAWSConfig struct {
func TestCreateQueueContainer(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
cfg := &TestAWSConfig{}
+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)},
+22 -6
View File
@@ -5,23 +5,39 @@ import (
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/objectstore"
"github.com/docker/go-connections/nat"
"github.com/gruntwork-io/terratest/modules/docker"
"github.com/stretchr/testify/assert"
)
func TestBuildImage(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
buildImage(t)
exists := docker.DoesImageExist(t, imageTag, nil)
assert.True(t, exists)
}
type Cfg struct {
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestCreateContainer(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
cfg := &serviceconfig.BaseConfig{}
cfg := &Cfg{}
net := DepNetwork.Get(t, ctx)
_ = CreateDB(t, ctx, cfg, net, &CreateDatabaseConfig{NoMigrations: true})
deps, clean := CreateFullDependencies(t, ctx, cfg)
defer clean()
ccfg := &containerConfig{
Name: string(QueryAPIName),
@@ -32,7 +48,7 @@ func TestCreateContainer(t *testing.T) {
},
}
container, cleanup := createContainer(t, ctx, net, ccfg)
container, cleanup := createContainer(t, ctx, deps.Network, ccfg)
assert.NotNil(t, container)
assert.NotNil(t, cleanup)
+2 -2
View File
@@ -13,7 +13,7 @@ import (
func TestCreateDB(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -29,7 +29,7 @@ func TestCreateDB(t *testing.T) {
func TestCreateDBWithMigrations(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -54,7 +54,7 @@ func TestCreateDetectDocumentTextExpectation(t *testing.T) {
func TestWaitForMockEndpoint(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+34 -26
View File
@@ -2,6 +2,7 @@ package test
import (
"context"
"fmt"
"log/slog"
"sync"
"testing"
@@ -29,34 +30,41 @@ func (nm *NetworkManager) Get(t testing.TB, ctx context.Context) string {
nm.mutex.Lock()
defer nm.mutex.Unlock()
if !nm.initialized {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
require.NoError(t, err)
nm.networkName = networkName
current, err := cli.NetworkList(ctx, network.ListOptions{})
require.NoError(t, err)
found := false
for _, c := range current {
if c.Name == nm.networkName {
found = true
continue
}
}
if !found {
_, err = cli.NetworkCreate(ctx, nm.networkName, network.CreateOptions{
Driver: "bridge",
})
require.NoError(t, err)
}
nm.initialized = true
if nm.initialized {
return nm.networkName
}
slog.Info("get network", "name", nm.networkName)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
require.NoError(t, err)
nm.networkName = networkName
current, err := cli.NetworkList(ctx, network.ListOptions{})
require.NoError(t, err)
found := false
for _, c := range current {
if c.Name == nm.networkName {
found = true
continue
}
}
if found {
return nm.networkName
}
_, err = cli.NetworkCreate(ctx, nm.networkName, network.CreateOptions{
Driver: "bridge",
})
conflictErrorMsg := fmt.Sprintf("Error response from daemon: network with name %s already exists", nm.networkName)
if err != nil && err.Error() != conflictErrorMsg {
require.NoError(t, err)
}
slog.Info("created network", "name", nm.networkName)
nm.initialized = true
return nm.networkName
}
+2 -2
View File
@@ -24,7 +24,7 @@ type StoreConfig struct {
func TestCreateBucket(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -40,7 +40,7 @@ func TestCreateBucket(t *testing.T) {
func TestCreateStoreClient(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+4 -4
View File
@@ -25,7 +25,7 @@ type TestConfig struct {
func TestCreateQueue(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -44,7 +44,7 @@ func TestCreateQueue(t *testing.T) {
func TestAssertMessageWait(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -71,7 +71,7 @@ func TestAssertMessageWait(t *testing.T) {
func TestAssertMessageBodyWait(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
@@ -95,7 +95,7 @@ func TestAssertMessageBodyWait(t *testing.T) {
func TestAssertMessageAttrWait(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()
+1 -1
View File
@@ -10,7 +10,7 @@ import (
func TestCreateRunner(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping long test in short mode")
t.SkipNow()
}
ctx := context.Background()