From f14bcc2309657f0ca7a8762fd9d72bbcb0815823 Mon Sep 17 00:00:00 2001 From: Marko Malenic Date: Tue, 3 Sep 2024 20:15:45 +1000 Subject: [PATCH] test(fmannotator): workaround for issue which expects a valid config.json --- .github/workflows/prbuild.yml | 1 + .../filemanager-build/src/gen_entities.rs | 2 ++ .../stateless/stacks/fmannotator/go.mod | 2 +- .../stacks/fmannotator/internal/test/test.go | 26 +++++++++++++++---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/prbuild.yml b/.github/workflows/prbuild.yml index 458f04681..979706173 100644 --- a/.github/workflows/prbuild.yml +++ b/.github/workflows/prbuild.yml @@ -96,6 +96,7 @@ jobs: rustc --version go version make --version + docker version - name: Checkout code uses: actions/checkout@v4 diff --git a/lib/workload/stateless/stacks/filemanager/filemanager-build/src/gen_entities.rs b/lib/workload/stateless/stacks/filemanager/filemanager-build/src/gen_entities.rs index a3d186a25..50511cfa3 100644 --- a/lib/workload/stateless/stacks/filemanager/filemanager-build/src/gen_entities.rs +++ b/lib/workload/stateless/stacks/filemanager/filemanager-build/src/gen_entities.rs @@ -17,6 +17,8 @@ use crate::Config; pub async fn generate_entities() -> Result<()> { let config = Config::load()?; + println!("{:#?}", config); + let out_dir = config.out_dir; let command: &[&_] = &[ "sea-orm-cli", diff --git a/lib/workload/stateless/stacks/fmannotator/go.mod b/lib/workload/stateless/stacks/fmannotator/go.mod index 00b7413ad..b4f499f47 100644 --- a/lib/workload/stateless/stacks/fmannotator/go.mod +++ b/lib/workload/stateless/stacks/fmannotator/go.mod @@ -5,6 +5,7 @@ go 1.22 require ( github.com/aws/aws-lambda-go v1.47.0 github.com/aws/aws-secretsmanager-caching-go v1.2.0 + github.com/docker/docker v27.1.1+incompatible github.com/docker/go-connections v0.5.0 github.com/go-testfixtures/testfixtures/v3 v3.12.0 github.com/google/uuid v1.6.0 @@ -31,7 +32,6 @@ require ( github.com/creack/pty v1.1.21 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/distribution/reference v0.6.0 // indirect - github.com/docker/docker v27.1.1+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-faster/city v1.0.1 // indirect diff --git a/lib/workload/stateless/stacks/fmannotator/internal/test/test.go b/lib/workload/stateless/stacks/fmannotator/internal/test/test.go index 4b2e65d43..93a7a85ec 100644 --- a/lib/workload/stateless/stacks/fmannotator/internal/test/test.go +++ b/lib/workload/stateless/stacks/fmannotator/internal/test/test.go @@ -5,6 +5,8 @@ import ( "database/sql" "encoding/json" "fmt" + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/go-testfixtures/testfixtures/v3" "github.com/google/uuid" @@ -14,6 +16,7 @@ import ( "github.com/testcontainers/testcontainers-go/wait" "github.com/umccr/orcabus/lib/workload/stateless/stacks/fmannotator/schema/orcabus_workflowmanager/workflowrunstatechange" "os" + "path" "path/filepath" "runtime" "strconv" @@ -41,16 +44,23 @@ func setupService(t *testing.T, buildContext string, port nat.Port, wait wait.St containerName := strings.ReplaceAll(strings.Trim(buildContext, "./"), "/", "_") req := testcontainers.ContainerRequest{ FromDockerfile: testcontainers.FromDockerfile{ - Context: buildContext, - Repo: containerName, - Tag: containerName, - BuildArgs: args, - KeepImage: true, + Context: buildContext, + Repo: containerName, + Tag: containerName, + BuildArgs: args, + KeepImage: true, + PrintBuildLog: true, + BuildOptionsModifier: func(options *types.ImageBuildOptions) { + options.ExtraHosts = []string{"host.docker.internal:host-gateway"} + }, }, ExposedPorts: []string{port.Port()}, Env: env, WaitingFor: wait, Name: containerName, + HostConfigModifier: func(config *container.HostConfig) { + config.ExtraHosts = []string{"host.docker.internal:host-gateway"} + }, } container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: req, @@ -81,6 +91,12 @@ func SetupFileManager(t *testing.T) *sql.DB { t.Setenv("TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT", "10m") t.Setenv("TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT", "5m") + // This works around an issue in test containers which requires the presence of a config.json file. + dir := t.TempDir() + err := os.WriteFile(path.Join(dir, "config.json"), []byte("{}"), 0666) + require.NoError(t, err) + t.Setenv("DOCKER_CONFIG", dir) + // Database testDatabaseName := fmt.Sprintf("filemanager_test_%v", strings.ReplaceAll(uuid.New().String(), "-", "_")) databaseIp, port := setupService(t, "../filemanager/database", "4321", wait.ForLog("database system is ready to accept connections").