Skip to content

Commit

Permalink
test(fmannotator): workaround for issue which expects a valid config.…
Browse files Browse the repository at this point in the history
…json
  • Loading branch information
mmalenic committed Sep 3, 2024
1 parent 3e1bee3 commit f14bcc2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/prbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:
rustc --version
go version
make --version
docker version
- name: Checkout code
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/workload/stateless/stacks/fmannotator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 21 additions & 5 deletions lib/workload/stateless/stacks/fmannotator/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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").
Expand Down

0 comments on commit f14bcc2

Please sign in to comment.