diff --git a/.golangci.yml b/.golangci.yml index 575f5777..9a2938af 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,7 @@ linters: - godox - cyclop - unused + - usetesting linters-settings: errcheck: diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 5daad09b..9b6f597f 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -9,7 +9,7 @@ definitions: services: docker: - memory: 16384 + memory: 12000 steps: - step: &fullsuite @@ -36,14 +36,60 @@ definitions: - devbox install - devbox run -- AWS_PROFILE="" task fullsuite - - docker save query-orchestration:latest -o dockerimage.tar - artifacts: - - dockerimage.tar + - step: &fullsuite-and-publish + name: Fullsuite and Publish + size: 16x + oidc: true + deployment: dev + services: + - docker + caches: + - devbox + - apt-lists + - apt-cache + script: + - export DOCKER_BUILDKIT=0 + - export DOCKER_HOST=tcp://localhost:2375 + - export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=tcp://localhost:2375 + - export TESTCONTAINERS_RYUK_DISABLED=true + - export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1} + - export IMAGE_TAG=$ECR_REGISTRY/doczy/query-orchestration:$BITBUCKET_COMMIT + - export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token + - echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token + + - rm /etc/apt/apt.conf.d/docker-clean || true + - apt-get update + - apt-get install -y curl git unzip + + - mkdir -p out + - cd out + + - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + - unzip awscliv2.zip + - ./aws/install + + - curl -fsSL https://get.jetify.com/devbox | bash -s -- -f + - export PATH="/root/.local/bin:$PATH" + - cd .. + + - aws sts get-caller-identity --query "Arn" --output text + - | + aws ecr get-login-password --region $AWS_DEFAULT_REGION | \ + docker login --username AWS --password-stdin $ECR_REGISTRY + + - touch .env + - devbox install + - devbox run -- AWS_PROFILE="" task fullsuite + + - docker tag queryorchestration:latest $IMAGE_TAG + - docker push $IMAGE_TAG + after-script: + - docker stop registry || true pipelines: branches: main: - - step: *fullsuite + - step: *fullsuite-and-publish pull-requests: "**": diff --git a/internal/client/create.go b/internal/client/create.go index 88b647e8..1755a104 100644 --- a/internal/client/create.go +++ b/internal/client/create.go @@ -46,7 +46,7 @@ func (s *Service) normalizeCreate(params *CreateParams) error { return nil } -// Make sure the char ~ never makes way in as a valid client id character +// NOTE: Make sure the char ~ never makes way in as a valid client id character // Reference bucket key filename const CLIENT_ID_REGEX = `[a-zA-Z0-9\_#-]+` diff --git a/internal/client/create_test.go b/internal/client/create_test.go index daf7c958..31e0c857 100644 --- a/internal/client/create_test.go +++ b/internal/client/create_test.go @@ -1,7 +1,6 @@ package client import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -13,7 +12,7 @@ import ( ) func TestCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/client/get_test.go b/internal/client/get_test.go index 40f7d72f..422a7a29 100644 --- a/internal/client/get_test.go +++ b/internal/client/get_test.go @@ -1,7 +1,6 @@ package client import ( - "context" "errors" "testing" @@ -14,7 +13,7 @@ import ( ) func TestGet(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/client/service.go b/internal/client/service.go index 6840b9b6..4a0100a8 100644 --- a/internal/client/service.go +++ b/internal/client/service.go @@ -14,28 +14,28 @@ type Client struct { CanSync bool } -func (c *Client) NormalizeCanSyncUpdate(n **bool) { - if n == nil || *n == nil { +func (c *Client) NormalizeCanSyncUpdate(canSync **bool) { + if canSync == nil || *canSync == nil { return } - if c.CanSync == **n { - *n = nil + if c.CanSync == **canSync { + *canSync = nil } } -func (c *Client) NormalizeNameUpdate(n **string) error { - if n == nil || *n == nil { +func (c *Client) NormalizeNameUpdate(name **string) error { + if name == nil || *name == nil { return nil } - err := normalizeName(*n) + err := normalizeName(*name) if err != nil { return err } - if c.Name == **n { - *n = nil + if c.Name == **name { + *name = nil } return nil @@ -46,18 +46,18 @@ func normalizeName(name *string) error { return nil } - uname := strings.TrimSpace(*name) - spacere := regexp.MustCompile(`\s+`) - uname = spacere.ReplaceAllString(uname, " ") + normalizedName := strings.TrimSpace(*name) + spaceRegex := regexp.MustCompile(`\s+`) + normalizedName = spaceRegex.ReplaceAllString(normalizedName, " ") - reg := `^[a-zA-Z0-9\_\- \(\)\.\,]+$` + validNameRegex := `^[a-zA-Z0-9\_\- \(\)\.\,]+$` - alphanumeric := regexp.MustCompile(reg) - if !alphanumeric.MatchString(uname) { - return fmt.Errorf(`"%s" must have regex: %s`, uname, reg) + alphanumeric := regexp.MustCompile(validNameRegex) + if !alphanumeric.MatchString(normalizedName) { + return fmt.Errorf(`"%s" must have regex: %s`, normalizedName, validNameRegex) } - *name = uname + *name = normalizedName return nil } diff --git a/internal/client/serviceprivate_test.go b/internal/client/serviceprivate_test.go index 8910e488..457cbf6e 100644 --- a/internal/client/serviceprivate_test.go +++ b/internal/client/serviceprivate_test.go @@ -34,51 +34,51 @@ func TestNormalizeName(t *testing.T) { } func TestNormalizeCanSyncUpdate(t *testing.T) { - c := Client{ + testClient := Client{ ID: "EXAMPLE", CanSync: true, } - c.NormalizeCanSyncUpdate(nil) - var val *bool - c.NormalizeCanSyncUpdate(&val) - assert.Nil(t, val) + testClient.NormalizeCanSyncUpdate(nil) + var updateCanSync *bool + testClient.NormalizeCanSyncUpdate(&updateCanSync) + assert.Nil(t, updateCanSync) - v := true - val = &v - c.NormalizeCanSyncUpdate(&val) - assert.Nil(t, val) + canSync := true + updateCanSync = &canSync + testClient.NormalizeCanSyncUpdate(&updateCanSync) + assert.Nil(t, updateCanSync) - v = false - val = &v - c.NormalizeCanSyncUpdate(&val) - assert.NotNil(t, *val) + canSync = false + updateCanSync = &canSync + testClient.NormalizeCanSyncUpdate(&updateCanSync) + assert.NotNil(t, *updateCanSync) } func TestNormalizeNameUpdate(t *testing.T) { - c := Client{ + testClient := Client{ ID: "EXAMPLE", Name: "example_name", } - err := c.NormalizeNameUpdate(nil) + err := testClient.NormalizeNameUpdate(nil) require.NoError(t, err) - v := "update_name" - val := &v - err = c.NormalizeNameUpdate(&val) + name := "update_name" + updateName := &name + err = testClient.NormalizeNameUpdate(&updateName) require.NoError(t, err) - assert.NotNil(t, val) - assert.Equal(t, "update_name", *val) + assert.NotNil(t, updateName) + assert.Equal(t, "update_name", *updateName) - v = c.Name - val = &v - err = c.NormalizeNameUpdate(&val) + name = testClient.Name + updateName = &name + err = testClient.NormalizeNameUpdate(&updateName) require.NoError(t, err) - assert.Nil(t, val) + assert.Nil(t, updateName) - v = "###" - val = &v - err = c.NormalizeNameUpdate(&val) + name = "###" + updateName = &name + err = testClient.NormalizeNameUpdate(&updateName) assert.Error(t, err) } diff --git a/internal/client/status_test.go b/internal/client/status_test.go index 320c174f..053458a9 100644 --- a/internal/client/status_test.go +++ b/internal/client/status_test.go @@ -1,7 +1,6 @@ package client_test import ( - "context" "errors" "testing" @@ -15,7 +14,7 @@ import ( ) func TestGetStatus(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/client/sync/sync_test.go b/internal/client/sync/sync_test.go index 50af87be..e4bb45c0 100644 --- a/internal/client/sync/sync_test.go +++ b/internal/client/sync/sync_test.go @@ -1,7 +1,6 @@ package clientsync import ( - "context" "fmt" "testing" @@ -25,7 +24,7 @@ type ClientSyncConfig struct { func TestTrigger(t *testing.T) { t.Run("two batches", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -86,7 +85,7 @@ func TestTrigger(t *testing.T) { require.NoError(t, err) }) t.Run("empty batch", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/client/update/update_test.go b/internal/client/update/update_test.go index c51c1341..ba0d7be5 100644 --- a/internal/client/update/update_test.go +++ b/internal/client/update/update_test.go @@ -1,7 +1,6 @@ package clientupdate import ( - "context" "fmt" "testing" @@ -25,7 +24,7 @@ type Config struct { } func TestUpdate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -119,7 +118,7 @@ func TestNormalizeUpdateParams(t *testing.T) { } func TestSubmitUpdate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -167,7 +166,7 @@ func TestSubmitUpdate(t *testing.T) { } func TestInformUpdate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &Config{} mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/cognitoauth/cognitotest/auth_full_test.go b/internal/cognitoauth/cognitotest/auth_full_test.go index f088a61d..78f59a1d 100644 --- a/internal/cognitoauth/cognitotest/auth_full_test.go +++ b/internal/cognitoauth/cognitotest/auth_full_test.go @@ -156,7 +156,7 @@ func TestCognitoAuthFlow(t *testing.T) { // Ensure server shuts down at the end of the test defer func() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second) defer cancel() if err := server.Shutdown(ctx); err != nil { t.Logf("Server shutdown error: %v", err) @@ -191,7 +191,7 @@ func TestCognitoAuthFlow(t *testing.T) { chromedp.Flag("disable-cache", true), ) - allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...) + allocCtx, cancel := chromedp.NewExecAllocator(t.Context(), opts...) defer cancel() // Create Chrome context with longer timeout for authentication flow diff --git a/internal/collector/get_test.go b/internal/collector/get_test.go index 05a3702b..7e187f88 100644 --- a/internal/collector/get_test.go +++ b/internal/collector/get_test.go @@ -1,7 +1,6 @@ package collector_test import ( - "context" "fmt" "testing" @@ -17,7 +16,7 @@ import ( ) func TestGetByClientID(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -50,7 +49,7 @@ func TestGetByClientID(t *testing.T) { } func TestListQueries(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/collector/set/set_test.go b/internal/collector/set/set_test.go index 7c3ab9b2..a57d9173 100644 --- a/internal/collector/set/set_test.go +++ b/internal/collector/set/set_test.go @@ -1,7 +1,6 @@ package collectorset_test import ( - "context" "fmt" "testing" @@ -25,7 +24,7 @@ type CollectorSetConfig struct { } func TestSet(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/collector/set/setprivate_test.go b/internal/collector/set/setprivate_test.go index 12101e9b..4232289a 100644 --- a/internal/collector/set/setprivate_test.go +++ b/internal/collector/set/setprivate_test.go @@ -1,7 +1,6 @@ package collectorset import ( - "context" "fmt" "testing" @@ -27,7 +26,7 @@ type CollectorSetConfig struct { func TestGetSetParams(t *testing.T) { t.Run("all params", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -84,7 +83,7 @@ func TestGetSetParams(t *testing.T) { }) t.Run("no params", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -104,7 +103,7 @@ func TestGetSetParams(t *testing.T) { }) t.Run("ONLY active version to next latest", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -130,7 +129,7 @@ func TestGetSetParams(t *testing.T) { }) t.Run("no fields change", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -161,7 +160,7 @@ func TestGetSetParams(t *testing.T) { func TestSubmitSet(t *testing.T) { t.Run("all fields", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -229,7 +228,7 @@ func TestSubmitSet(t *testing.T) { }) t.Run("only active version", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -517,7 +516,7 @@ func TestGetAddFields(t *testing.T) { func TestNormalizeSetFieldsToDB(t *testing.T) { t.Run("valid key", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -550,7 +549,7 @@ func TestNormalizeSetFieldsToDB(t *testing.T) { }) t.Run("duplicate values", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -578,7 +577,7 @@ func TestNormalizeSetFieldsToDB(t *testing.T) { assert.Error(t, err) }) t.Run("no changes", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &CollectorSetConfig{} svc := Service{ @@ -603,7 +602,7 @@ func TestNormalizeSetFieldsToDB(t *testing.T) { func TestInformSet(t *testing.T) { t.Run("with version update", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -636,7 +635,7 @@ func TestInformSet(t *testing.T) { require.NoError(t, err) }) t.Run("with no update", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -659,7 +658,7 @@ func TestInformSet(t *testing.T) { } func TestNormalizeFieldsToDB(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/database/migrationsprivate_test.go b/internal/database/migrationsprivate_test.go index 9adf4458..99c48fc1 100644 --- a/internal/database/migrationsprivate_test.go +++ b/internal/database/migrationsprivate_test.go @@ -1,7 +1,6 @@ package database import ( - "context" "testing" "queryorchestration/internal/serviceconfig/database" @@ -10,7 +9,7 @@ import ( ) func TestCreateDB(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &database.DBConfig{ DBHost: "invalid_value", } diff --git a/internal/database/repository/clean_test.go b/internal/database/repository/clean_test.go index 682a6c19..ee8866d7 100644 --- a/internal/database/repository/clean_test.go +++ b/internal/database/repository/clean_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -17,7 +16,7 @@ func TestClean(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) diff --git a/internal/database/repository/client_test.go b/internal/database/repository/client_test.go index 01499e74..b350012e 100644 --- a/internal/database/repository/client_test.go +++ b/internal/database/repository/client_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -17,7 +16,7 @@ func TestClientQueries(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) diff --git a/internal/database/repository/collector_test.go b/internal/database/repository/collector_test.go index 58c1611b..20823bf0 100644 --- a/internal/database/repository/collector_test.go +++ b/internal/database/repository/collector_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "fmt" "testing" @@ -19,7 +18,7 @@ func TestCollector(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -221,7 +220,7 @@ func TestCollector(t *testing.T) { } func BenchmarkListCollectorQueries(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) @@ -243,7 +242,7 @@ func BenchmarkListCollectorQueries(b *testing.B) { } func BenchmarkGetCollectorByClientID(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) diff --git a/internal/database/repository/db_test.go b/internal/database/repository/db_test.go index 1336ae8b..3f38dff8 100644 --- a/internal/database/repository/db_test.go +++ b/internal/database/repository/db_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -21,7 +20,7 @@ func TestQueriesNew(t *testing.T) { } func TestQueriesWithTx(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/database/repository/document_test.go b/internal/database/repository/document_test.go index 81352049..0d225f55 100644 --- a/internal/database/repository/document_test.go +++ b/internal/database/repository/document_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -18,7 +17,7 @@ func TestDocument(t *testing.T) { } t.Run("List docs for a client", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -38,7 +37,7 @@ func TestDocument(t *testing.T) { }) t.Run("Create document", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -68,7 +67,7 @@ func TestDocument(t *testing.T) { t.Run("Create two documents", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -103,7 +102,7 @@ func TestDocument(t *testing.T) { }) t.Run("Two clients", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -149,7 +148,7 @@ func TestDocument(t *testing.T) { }) t.Run("document summary", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -181,7 +180,7 @@ func TestDocument(t *testing.T) { }) t.Run("document external", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -214,7 +213,7 @@ func TestDocument(t *testing.T) { }) t.Run("doc id by hash", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -245,7 +244,7 @@ func TestDocument(t *testing.T) { }) t.Run("doc entry", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -286,7 +285,7 @@ func TestDocument(t *testing.T) { }) t.Run("doc latest entry", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) diff --git a/internal/database/repository/query_test.go b/internal/database/repository/query_test.go index d50e7275..bb78eaa4 100644 --- a/internal/database/repository/query_test.go +++ b/internal/database/repository/query_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -18,7 +17,7 @@ func TestQueries(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -227,7 +226,7 @@ func TestQueryDependencyTree(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -445,7 +444,7 @@ func TestQueriesList(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -500,7 +499,7 @@ func TestListQueryClients(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -588,7 +587,7 @@ func TestListQueryClients(t *testing.T) { } func BenchmarkListQueryDirectDependentsByDocId(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) diff --git a/internal/database/repository/result_test.go b/internal/database/repository/result_test.go index 8f0fcec3..adc7a832 100644 --- a/internal/database/repository/result_test.go +++ b/internal/database/repository/result_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "time" @@ -20,7 +19,7 @@ func TestResults(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -47,7 +46,7 @@ func TestResultValues(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -376,7 +375,7 @@ func TestUnsyncedNoDepsQueries(t *testing.T) { t.Run("two files", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -472,7 +471,7 @@ func TestUnsyncedNoDepsQueries(t *testing.T) { t.Run("update query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -499,7 +498,7 @@ func TestUnsyncedNoDepsQueries(t *testing.T) { } func BenchmarkListUnsynced(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) diff --git a/internal/database/repository/sync_test.go b/internal/database/repository/sync_test.go index 70bf6dac..124faf75 100644 --- a/internal/database/repository/sync_test.go +++ b/internal/database/repository/sync_test.go @@ -20,7 +20,7 @@ func TestListClientDocumentIDs(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -197,7 +197,7 @@ func TestClientSync(t *testing.T) { t.Run("no collector", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -218,7 +218,7 @@ func TestClientSync(t *testing.T) { t.Run("no documents", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -247,7 +247,7 @@ func TestClientSync(t *testing.T) { t.Run("create document", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -282,7 +282,7 @@ func TestClientSync(t *testing.T) { t.Run("document fail clean", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -318,7 +318,7 @@ func TestClientSync(t *testing.T) { t.Run("clean document", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -360,7 +360,7 @@ func TestClientSync(t *testing.T) { t.Run("extracted text", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -400,7 +400,7 @@ func TestClientSync(t *testing.T) { t.Run("single query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -430,7 +430,7 @@ func TestClientSync(t *testing.T) { t.Run("change super query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -460,7 +460,7 @@ func TestClientSync(t *testing.T) { }) t.Run("upstream query update result", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -504,7 +504,7 @@ func TestClientSync(t *testing.T) { t.Run("update upstream query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -564,7 +564,7 @@ func TestClientSync(t *testing.T) { t.Run("update text entry", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -602,7 +602,7 @@ func TestClientSync(t *testing.T) { }) t.Run("update text entry result", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -648,7 +648,7 @@ func TestClientSync(t *testing.T) { }) t.Run("update clean entry", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -689,7 +689,7 @@ func TestClientSync(t *testing.T) { }) t.Run("update clean entry with result", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -756,7 +756,7 @@ func TestClientSync(t *testing.T) { t.Run("add new collector version", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -781,7 +781,7 @@ func TestClientSync(t *testing.T) { t.Run("add new active collector version", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -812,7 +812,7 @@ func TestClientSync(t *testing.T) { t.Run("remove query from new collector version", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -843,7 +843,7 @@ func TestClientSync(t *testing.T) { }) t.Run("remove query and update collector version", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -881,7 +881,7 @@ func TestClientSync(t *testing.T) { t.Run("add existing query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -911,7 +911,7 @@ func TestClientSync(t *testing.T) { t.Run("add super query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -940,7 +940,7 @@ func TestClientSync(t *testing.T) { }) t.Run("add super query with result", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -1102,7 +1102,7 @@ func createDocumentWithCollectorAndResults(t testing.TB, queries *repository.Que } func BenchmarkIsClientSynced(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) @@ -1121,7 +1121,7 @@ func BenchmarkIsClientSynced(b *testing.B) { } func BenchmarkGetDocumentExternal(b *testing.B) { - ctx := context.Background() + ctx := b.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(b, cfg) diff --git a/internal/database/repository/text_test.go b/internal/database/repository/text_test.go index 5e37eab3..52bcfe49 100644 --- a/internal/database/repository/text_test.go +++ b/internal/database/repository/text_test.go @@ -1,7 +1,6 @@ package repository_test import ( - "context" "testing" "time" @@ -20,7 +19,7 @@ func TestTextExtraction(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -127,7 +126,7 @@ func TestTextTextractPart(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) @@ -256,7 +255,7 @@ func TestTextOutPart(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) diff --git a/internal/document/clean/clean_test.go b/internal/document/clean/clean_test.go index e2136013..aaed4bd7 100644 --- a/internal/document/clean/clean_test.go +++ b/internal/document/clean/clean_test.go @@ -1,7 +1,6 @@ package documentclean import ( - "context" "io" "strings" "testing" @@ -23,7 +22,7 @@ import ( ) func TestClean(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -113,7 +112,7 @@ func TestClean(t *testing.T) { } func TestExecuteCleanTasks(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) @@ -172,7 +171,7 @@ func TestExecuteCleanTasks(t *testing.T) { } func TestStoreClean(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/clean/contentType_test.go b/internal/document/clean/contentType_test.go index 30f26f09..2b00b02d 100644 --- a/internal/document/clean/contentType_test.go +++ b/internal/document/clean/contentType_test.go @@ -1,7 +1,6 @@ package documentclean import ( - "context" "fmt" "io" "strings" @@ -21,7 +20,7 @@ import ( func TestGetBodyMimeType(t *testing.T) { t.Run("invalid type", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -59,7 +58,7 @@ func TestGetBodyMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypeInvalid, contentType) }) t.Run("pdf", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -108,7 +107,7 @@ func TestGetBodyMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypePDF, contentType) }) t.Run("pdf start", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -157,7 +156,7 @@ func TestGetBodyMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypeInvalid, contentType) }) t.Run("pdf end", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -206,7 +205,7 @@ func TestGetBodyMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypeInvalid, contentType) }) t.Run("short", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -269,7 +268,7 @@ func TestGetMetadataMimeType(t *testing.T) { func TestGetAcceptedMimeType(t *testing.T) { t.Run("invalid type", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -307,7 +306,7 @@ func TestGetAcceptedMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypeInvalid, contentType) }) t.Run("pdf mimetype", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -320,7 +319,7 @@ func TestGetAcceptedMimeType(t *testing.T) { assert.Equal(t, documenttypes.MimeTypePDF, contentType) }) t.Run("pdf format", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -372,7 +371,7 @@ func TestGetAcceptedMimeType(t *testing.T) { func TestGetBytesBuffer(t *testing.T) { t.Run("valid", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -412,7 +411,7 @@ func TestGetBytesBuffer(t *testing.T) { assert.NotNil(t, buffer) }) t.Run("negative start", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 @@ -452,7 +451,7 @@ func TestGetBytesBuffer(t *testing.T) { assert.NotNil(t, buffer) }) t.Run("zero length", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &DocCleanConfig{} mockS3 := objectstoremock.NewMockS3Client(t) cfg.StoreClient = mockS3 diff --git a/internal/document/clean/create_test.go b/internal/document/clean/create_test.go index e940103d..c9f80283 100644 --- a/internal/document/clean/create_test.go +++ b/internal/document/clean/create_test.go @@ -1,7 +1,6 @@ package documentclean import ( - "context" "fmt" "io" "strings" @@ -33,7 +32,7 @@ type DocCleanConfig struct { } func TestCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -139,7 +138,7 @@ func TestCreate(t *testing.T) { } func TestInformClean(t *testing.T) { - ctx := context.Background() + ctx := t.Context() mockSQS := queuemock.NewMockSQSClient(t) cfg := &DocCleanConfig{} diff --git a/internal/document/get_test.go b/internal/document/get_test.go index 2dd29d4d..6d631670 100644 --- a/internal/document/get_test.go +++ b/internal/document/get_test.go @@ -1,7 +1,6 @@ package document_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -16,7 +15,7 @@ import ( ) func TestGetSummary(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -44,7 +43,7 @@ func TestGetSummary(t *testing.T) { } func TestGetExternal(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/init/create_test.go b/internal/document/init/create_test.go index 535a2a61..ed76a258 100644 --- a/internal/document/init/create_test.go +++ b/internal/document/init/create_test.go @@ -1,7 +1,6 @@ package documentinit import ( - "context" "errors" "fmt" "testing" @@ -22,7 +21,7 @@ import ( ) func TestCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -95,7 +94,7 @@ func TestCreate(t *testing.T) { } func TestGetCreateParams(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -135,7 +134,7 @@ func TestGetCreateParams(t *testing.T) { } func TestGetCreateParamsExisting(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -179,7 +178,7 @@ func TestGetCreateParamsExisting(t *testing.T) { } func TestGetCreateParamsCurrentDocErr(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -212,7 +211,7 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) { } func TestSubmitCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -255,7 +254,7 @@ func TestSubmitCreate(t *testing.T) { } func TestSubmitCreateExists(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/list_test.go b/internal/document/list_test.go index 678945e8..37e90ad8 100644 --- a/internal/document/list_test.go +++ b/internal/document/list_test.go @@ -1,7 +1,6 @@ package document_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -15,7 +14,7 @@ import ( ) func TestListByClientId(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/store/process_test.go b/internal/document/store/process_test.go index c811626e..1169da5c 100644 --- a/internal/document/store/process_test.go +++ b/internal/document/store/process_test.go @@ -1,7 +1,6 @@ package documentstore import ( - "context" "testing" "time" @@ -21,7 +20,7 @@ type ProcessConfig struct { } func TestProcess(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &ProcessConfig{} mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/document/sync/sync_test.go b/internal/document/sync/sync_test.go index 28b70de2..7b420e07 100644 --- a/internal/document/sync/sync_test.go +++ b/internal/document/sync/sync_test.go @@ -1,7 +1,6 @@ package documentsync_test import ( - "context" "fmt" "testing" @@ -20,7 +19,7 @@ import ( ) func TestSync(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/text/documentText_test.go b/internal/document/text/documentText_test.go index 73cc8677..65e86b8b 100644 --- a/internal/document/text/documentText_test.go +++ b/internal/document/text/documentText_test.go @@ -21,7 +21,7 @@ import ( ) func TestGetDocumentText(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("Hello World", func(t *testing.T) { t.Parallel() diff --git a/internal/document/text/execute_test.go b/internal/document/text/execute_test.go index 8108924d..bccfa27b 100644 --- a/internal/document/text/execute_test.go +++ b/internal/document/text/execute_test.go @@ -1,7 +1,6 @@ package documenttext import ( - "context" "io" "strings" "testing" @@ -20,7 +19,7 @@ import ( ) func TestExecuteExtract(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/text/extract_test.go b/internal/document/text/extract_test.go index 0ebd040e..572f145d 100644 --- a/internal/document/text/extract_test.go +++ b/internal/document/text/extract_test.go @@ -1,7 +1,6 @@ package documenttext import ( - "context" "fmt" "io" "strings" @@ -35,7 +34,7 @@ type DocTextConfig struct { } func TestCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -141,7 +140,7 @@ func TestCreate(t *testing.T) { } func TestInformClean(t *testing.T) { - ctx := context.Background() + ctx := t.Context() mockSQS := queuemock.NewMockSQSClient(t) cfg := &DocTextConfig{} diff --git a/internal/document/text/pageText_test.go b/internal/document/text/pageText_test.go index 6a52b950..45176246 100644 --- a/internal/document/text/pageText_test.go +++ b/internal/document/text/pageText_test.go @@ -1,7 +1,6 @@ package documenttext import ( - "context" "io" "testing" @@ -16,7 +15,7 @@ import ( ) func TestGetBasePage(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := DocTextConfig{} svc := Service{ cfg: &cfg, diff --git a/internal/document/text/storeExtract_test.go b/internal/document/text/storeExtract_test.go index caec02fd..c2487a71 100644 --- a/internal/document/text/storeExtract_test.go +++ b/internal/document/text/storeExtract_test.go @@ -1,7 +1,6 @@ package documenttext import ( - "context" "database/sql" "io" "strings" @@ -22,7 +21,7 @@ import ( ) func TestStoreExtract(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/document/types/pdf_test.go b/internal/document/types/pdf_test.go index 5f5fd132..bd969fdd 100644 --- a/internal/document/types/pdf_test.go +++ b/internal/document/types/pdf_test.go @@ -1,7 +1,6 @@ package documenttypes import ( - "context" "math" "os" "path/filepath" @@ -15,7 +14,7 @@ import ( ) func TestIsValidDPI(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("no imgs", func(t *testing.T) { pdf := NewPDF(strings.NewReader(pdfHelloWorld)) @@ -133,7 +132,7 @@ func TestIsValidDPI(t *testing.T) { } func TestIsValidDimensions(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("valid", func(t *testing.T) { pdf := NewPDF(strings.NewReader(pdfHelloWorld)) @@ -168,7 +167,7 @@ func TestIsValidDimensions(t *testing.T) { } func TestGetPageCount(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("valid", func(t *testing.T) { pdf := NewPDF(strings.NewReader(pdfHelloWorld)) @@ -186,7 +185,7 @@ func TestGetPageCount(t *testing.T) { } func TestIsCorrupt(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("valid", func(t *testing.T) { pdf := NewPDF(strings.NewReader(pdfHelloWorld)) @@ -255,7 +254,7 @@ func TestNewPDF(t *testing.T) { } func TestPDFGetPage(t *testing.T) { - ctx := context.Background() + ctx := t.Context() t.Run("hello world", func(t *testing.T) { file, err := os.Open("../../../assets/original/version1_7.pdf") require.NoError(t, err) diff --git a/internal/query/create_test.go b/internal/query/create_test.go index 82c8d13d..b0b82ede 100644 --- a/internal/query/create_test.go +++ b/internal/query/create_test.go @@ -1,7 +1,6 @@ package query_test import ( - "context" "errors" "testing" @@ -19,7 +18,7 @@ import ( ) func TestCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -75,7 +74,7 @@ func TestCreate(t *testing.T) { } func TestCreateMinimal(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -114,7 +113,7 @@ func TestCreateMinimal(t *testing.T) { } func TestCreateRollback(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/createprivate_test.go b/internal/query/createprivate_test.go index b61efb25..9c21cf49 100644 --- a/internal/query/createprivate_test.go +++ b/internal/query/createprivate_test.go @@ -1,7 +1,6 @@ package query import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -74,7 +73,7 @@ func TestParseCreateQueryInvalidType(t *testing.T) { } func TestSubmitCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -126,7 +125,7 @@ func TestSubmitCreate(t *testing.T) { } func TestSubmitCreateNoReqsOrConfig(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -165,7 +164,7 @@ func TestSubmitCreateNoReqsOrConfig(t *testing.T) { } func TestNormalizeCreate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/get_test.go b/internal/query/get_test.go index 2c27258a..49c3159f 100644 --- a/internal/query/get_test.go +++ b/internal/query/get_test.go @@ -1,7 +1,6 @@ package query_test import ( - "context" "testing" "time" @@ -19,7 +18,7 @@ import ( ) func TestGet(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -149,7 +148,7 @@ func TestGetWithVersion(t *testing.T) { Addedversion: latestVersion, }) require.NoError(t, err) - ctx := context.Background() + ctx := t.Context() svc := query.New(cfg) diff --git a/internal/query/list_test.go b/internal/query/list_test.go index 97777821..a9e9a514 100644 --- a/internal/query/list_test.go +++ b/internal/query/list_test.go @@ -1,7 +1,6 @@ package query_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -17,7 +16,7 @@ import ( ) func TestList(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -52,7 +51,7 @@ func TestList(t *testing.T) { } func TestListById(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/normalize_test.go b/internal/query/normalize_test.go index 2b246e01..523a2cfe 100644 --- a/internal/query/normalize_test.go +++ b/internal/query/normalize_test.go @@ -1,7 +1,6 @@ package query import ( - "context" "errors" "testing" @@ -70,7 +69,7 @@ func TestNormalizeConfig(t *testing.T) { } func TestNormalizeQueryIDs(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/result/process_test.go b/internal/query/result/process_test.go index 5ad73878..68c16cd9 100644 --- a/internal/query/result/process_test.go +++ b/internal/query/result/process_test.go @@ -1,7 +1,6 @@ package result import ( - "context" "testing" "time" @@ -140,7 +139,7 @@ func TestProcess(t *testing.T) { } func TestListRequiredValue(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/result/set/set_test.go b/internal/query/result/set/set_test.go index d7cc958c..ad0921c9 100644 --- a/internal/query/result/set/set_test.go +++ b/internal/query/result/set/set_test.go @@ -1,7 +1,6 @@ package resultset import ( - "context" "fmt" "testing" @@ -28,7 +27,7 @@ type ResultSetConfig struct { } func TestSet(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -121,7 +120,7 @@ func TestSet(t *testing.T) { } func TestInformQueryDependents(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/result/sync/trigger_test.go b/internal/query/result/sync/trigger_test.go index d4fcd274..f3d5b138 100644 --- a/internal/query/result/sync/trigger_test.go +++ b/internal/query/result/sync/trigger_test.go @@ -1,7 +1,6 @@ package resultsync import ( - "context" "fmt" "testing" @@ -22,7 +21,7 @@ type ResultSyncConfig struct { } func TestTriggerSync(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &ResultSyncConfig{} mockSQS := queuemock.NewMockSQSClient(t) @@ -53,7 +52,7 @@ func TestTriggerSync(t *testing.T) { } func TestTriggerMultiSync(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &ResultSyncConfig{} mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/query/sync/sync_test.go b/internal/query/sync/sync_test.go index 2bbe21fd..9b50e024 100644 --- a/internal/query/sync/sync_test.go +++ b/internal/query/sync/sync_test.go @@ -1,7 +1,6 @@ package querysync import ( - "context" "fmt" "testing" @@ -25,7 +24,7 @@ type QuerySyncConfig struct { } func TestSync(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) cfg := &QuerySyncConfig{} diff --git a/internal/query/test/test_test.go b/internal/query/test/test_test.go index 8a6c3440..d0ed50d7 100644 --- a/internal/query/test/test_test.go +++ b/internal/query/test/test_test.go @@ -1,7 +1,6 @@ package querytest_test import ( - "context" "testing" "queryorchestration/internal/collector" @@ -20,7 +19,7 @@ import ( ) func TestTest(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/types/contextFull/process_test.go b/internal/query/types/contextFull/process_test.go index 2c2600db..4210845d 100644 --- a/internal/query/types/contextFull/process_test.go +++ b/internal/query/types/contextFull/process_test.go @@ -1,7 +1,6 @@ package contextfull_test import ( - "context" "testing" resultprocessor "queryorchestration/internal/query/result/processor" @@ -13,7 +12,7 @@ import ( ) func TestContextFull(t *testing.T) { - ctx := context.Background() + ctx := t.Context() extractor := contextfull.NewExtractor() diff --git a/internal/query/types/jsonExtractor/process_test.go b/internal/query/types/jsonExtractor/process_test.go index b2b03fd4..daec7bab 100644 --- a/internal/query/types/jsonExtractor/process_test.go +++ b/internal/query/types/jsonExtractor/process_test.go @@ -1,7 +1,6 @@ package jsonextractor_test import ( - "context" "fmt" "testing" @@ -19,7 +18,7 @@ import ( ) func TestJSONProcess(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -79,7 +78,7 @@ func TestJSONProcess(t *testing.T) { } func TestJSONProcessJSON(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} @@ -128,7 +127,7 @@ func TestJSONProcessJSON(t *testing.T) { } func TestJSONProcessResults(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} diff --git a/internal/query/update/update_test.go b/internal/query/update/update_test.go index ccf2f475..1d631c61 100644 --- a/internal/query/update/update_test.go +++ b/internal/query/update/update_test.go @@ -1,7 +1,6 @@ package queryupdate_test import ( - "context" "fmt" "testing" @@ -28,7 +27,7 @@ type QueryUpdateConfig struct { } func TestUpdate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) diff --git a/internal/query/update/updateprivate_test.go b/internal/query/update/updateprivate_test.go index 911c55f9..b12ff78a 100644 --- a/internal/query/update/updateprivate_test.go +++ b/internal/query/update/updateprivate_test.go @@ -1,7 +1,6 @@ package queryupdate import ( - "context" "errors" "fmt" "testing" @@ -50,7 +49,7 @@ func TestGetUpdator(t *testing.T) { } func TestSubmitUpdate(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -101,7 +100,7 @@ func TestSubmitUpdate(t *testing.T) { } func TestSubmitUpdateRollback(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -136,7 +135,7 @@ func TestSubmitUpdateRollback(t *testing.T) { func TestSubmitUpdateRequiredQueries(t *testing.T) { t.Run("all fields", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -188,7 +187,7 @@ func TestSubmitUpdateRequiredQueries(t *testing.T) { }) t.Run("all nil", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -228,7 +227,7 @@ func TestSubmitUpdateRequiredQueries(t *testing.T) { } func TestSubmitUpdateActiveVersion(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -274,7 +273,7 @@ func TestGetSetDifference(t *testing.T) { func TestNormalizeUpdate(t *testing.T) { t.Run("all fields to change", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -311,7 +310,7 @@ func TestNormalizeUpdate(t *testing.T) { }) t.Run("no changes", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -336,7 +335,7 @@ func TestNormalizeUpdate(t *testing.T) { }) t.Run("same active version", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -363,7 +362,7 @@ func TestNormalizeUpdate(t *testing.T) { }) t.Run("ONLY active version to next latest", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -392,7 +391,7 @@ func TestNormalizeUpdate(t *testing.T) { func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { t.Run("Empty Array", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -420,7 +419,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { }) t.Run("entry doesn't exist", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -450,7 +449,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { assert.Error(t, err) }) t.Run("in dependency tree", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) @@ -484,7 +483,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { assert.Error(t, err) }) t.Run("same update and current", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) cfg := &QueryUpdateConfig{} @@ -525,7 +524,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { func TestInformUpdate(t *testing.T) { t.Run("nil active version", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &QueryUpdateConfig{} mockSQS := queuemock.NewMockSQSClient(t) @@ -544,7 +543,7 @@ func TestInformUpdate(t *testing.T) { require.NoError(t, err) }) t.Run("update active version", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &QueryUpdateConfig{} mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/query/versionsync/sync_test.go b/internal/query/versionsync/sync_test.go index 407812af..ff0e0ce4 100644 --- a/internal/query/versionsync/sync_test.go +++ b/internal/query/versionsync/sync_test.go @@ -1,7 +1,6 @@ package queryversionsync import ( - "context" "fmt" "testing" @@ -25,7 +24,7 @@ type QueryVersionSyncConfig struct { } func TestSync(t *testing.T) { - ctx := context.Background() + ctx := t.Context() pool, err := pgxmock.NewPool() require.NoError(t, err) cfg := &QueryVersionSyncConfig{} diff --git a/internal/server/api/listener_test.go b/internal/server/api/listener_test.go index 26939f1a..6350442c 100644 --- a/internal/server/api/listener_test.go +++ b/internal/server/api/listener_test.go @@ -1,7 +1,6 @@ package api import ( - "context" "log/slog" "net/http" "net/http/httptest" @@ -24,7 +23,7 @@ func TestNewAPI(t *testing.T) { t.SkipNow() } t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &BaseConfig{} _ = serviceconfig.InitializeConfig(cfg) @@ -126,9 +125,9 @@ func TestGetDebugMiddleware(t *testing.T) { t.Run("debug disabled", func(t *testing.T) { // Save original env and restore after test origDebug := os.Getenv("DEBUG") - defer os.Setenv("DEBUG", origDebug) + defer t.Setenv("DEBUG", origDebug) - os.Setenv("DEBUG", "false") + t.Setenv("DEBUG", "false") // Reset logs l.Logs = nil @@ -163,9 +162,9 @@ func TestGetDebugMiddleware(t *testing.T) { t.Run("debug enabled", func(t *testing.T) { // Save original env and restore after test origDebug := os.Getenv("DEBUG") - defer os.Setenv("DEBUG", origDebug) + defer t.Setenv("DEBUG", origDebug) - os.Setenv("DEBUG", "true") + t.Setenv("DEBUG", "true") // Reset logs l.Logs = nil diff --git a/internal/server/runner/listener_test.go b/internal/server/runner/listener_test.go index 29e548f6..340a3f05 100644 --- a/internal/server/runner/listener_test.go +++ b/internal/server/runner/listener_test.go @@ -1,7 +1,6 @@ package runner import ( - "context" "sync" "testing" @@ -59,7 +58,7 @@ func TestNewRunner(t *testing.T) { } func TestListen(t *testing.T) { - ctx := context.Background() + ctx := t.Context() queue := Server[interface{}]{} @@ -81,7 +80,7 @@ func TestRegisterController(t *testing.T) { } func TestPingQueue(t *testing.T) { - ctx := context.Background() + ctx := t.Context() c := BaseConfig[interface{}]{} c.QueueURL = "i/am/here" mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/server/server_test.go b/internal/server/server_test.go index 224e8cc9..5d7a3b92 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -1,7 +1,6 @@ package server_test import ( - "context" "fmt" "testing" @@ -19,7 +18,7 @@ func TestNewServer(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &server.BaseConfig{} _ = serviceconfig.InitializeConfig(cfg) diff --git a/internal/serviceconfig/auth/config_test.go b/internal/serviceconfig/auth/config_test.go index 2fd1f688..c1dd267f 100644 --- a/internal/serviceconfig/auth/config_test.go +++ b/internal/serviceconfig/auth/config_test.go @@ -26,7 +26,7 @@ func TestInitializeAuthConfig(t *testing.T) { // Set environment variables for k, v := range testEnv { - os.Setenv(k, v) + t.Setenv(k, v) } defer func() { // Cleanup environment variables after test @@ -47,7 +47,6 @@ func TestInitializeAuthConfig(t *testing.T) { // Create config instance cfg := &CognitoConfig{} err := cfg.InitializeAuthConfig(baseURL, testLogger) - // Test initialization success if err != nil { t.Errorf("InitializeAuthConfig failed: %v", err) @@ -107,10 +106,10 @@ func TestInitializeAuthConfigWithDefaults(t *testing.T) { } // Set required variables - os.Setenv("COGNITO_USER_POOL_ID", "us-east-2_testpool") - os.Setenv("COGNITO_CLIENT_ID", "test-client-id") - os.Setenv("COGNITO_CLIENT_SECRET", "test-client-secret") - os.Setenv("COGNITO_DOMAIN", "test-domain.auth.us-east-2.amazoncognito.com") + t.Setenv("COGNITO_USER_POOL_ID", "us-east-2_testpool") + t.Setenv("COGNITO_CLIENT_ID", "test-client-id") + t.Setenv("COGNITO_CLIENT_SECRET", "test-client-secret") + t.Setenv("COGNITO_DOMAIN", "test-domain.auth.us-east-2.amazoncognito.com") defer func() { for _, env := range append(envVars, "COGNITO_USER_POOL_ID", "COGNITO_CLIENT_ID", "COGNITO_CLIENT_SECRET", "COGNITO_DOMAIN") { @@ -120,7 +119,6 @@ func TestInitializeAuthConfigWithDefaults(t *testing.T) { cfg := &CognitoConfig{} err := cfg.InitializeAuthConfig("https://example.com", nil) - if err != nil { t.Errorf("InitializeAuthConfig failed: %v", err) } @@ -302,7 +300,7 @@ func TestGettersAndSetters(t *testing.T) { func TestPrettyPrintDebugOnly(t *testing.T) { // Test with DEBUG=true - os.Setenv("DEBUG", "true") + t.Setenv("DEBUG", "true") defer os.Unsetenv("DEBUG") cfg := &CognitoConfig{ @@ -353,9 +351,8 @@ func TestPrettyPrintDebugOnly(t *testing.T) { } // Test with DEBUG=false - os.Setenv("DEBUG", "false") + t.Setenv("DEBUG", "false") buf.Reset() cfg.PrettyPrintDebugOnly() - } diff --git a/internal/serviceconfig/common_test.go b/internal/serviceconfig/common_test.go index 5951dccb..67ab6c0d 100644 --- a/internal/serviceconfig/common_test.go +++ b/internal/serviceconfig/common_test.go @@ -1,7 +1,6 @@ package serviceconfig import ( - "os" "strings" "testing" @@ -94,10 +93,6 @@ func TestInitializeConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Clear environment at the start of each subtest - os.Clearenv() - - // Set environment variables for this test case for k, v := range tt.envVars { t.Setenv(k, v) } @@ -139,13 +134,10 @@ func TestInitializeConfig(t *testing.T) { } }) } - os.Clearenv() - } func TestGetBaseConfig(t *testing.T) { assert.NotNil(t, getBaseConfig(&BaseConfig{})) assert.Nil(t, getBaseConfig(nil)) assert.NotNil(t, getBaseConfig(&initializeConfigTestStruct{})) - os.Clearenv() } diff --git a/internal/serviceconfig/commonlog_test.go b/internal/serviceconfig/commonlog_test.go index 47d65c12..ece3f6e8 100644 --- a/internal/serviceconfig/commonlog_test.go +++ b/internal/serviceconfig/commonlog_test.go @@ -3,7 +3,6 @@ package serviceconfig_test import ( "bytes" "log/slog" - "os" "strings" "testing" @@ -15,7 +14,6 @@ import ( // TestPrintConfigRecursive tests the PrintConfigRecursive function as a blackbox test. func TestPrintConfigRecursive(t *testing.T) { serviceconfig.ResetConfigInitOnceTestOnly() - os.Clearenv() envVars := map[string]string{ "PGUSER": "postgres", "PGPASSWORD": "password", diff --git a/internal/serviceconfig/database/pool_test.go b/internal/serviceconfig/database/pool_test.go index a4f5c58d..a56ddd02 100644 --- a/internal/serviceconfig/database/pool_test.go +++ b/internal/serviceconfig/database/pool_test.go @@ -1,7 +1,6 @@ package database_test import ( - "context" "testing" "queryorchestration/internal/database/repository" @@ -18,7 +17,7 @@ func TestSetDBPool(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &serviceconfig.BaseConfig{} test.CreateDB(t, cfg) diff --git a/internal/serviceconfig/objectstore/config_test.go b/internal/serviceconfig/objectstore/config_test.go index cf86cb30..8e9c8997 100644 --- a/internal/serviceconfig/objectstore/config_test.go +++ b/internal/serviceconfig/objectstore/config_test.go @@ -3,7 +3,6 @@ package objectstore_test import ( "context" "errors" - "os" "strings" "testing" "time" @@ -32,8 +31,7 @@ func TestGetStoreClient(t *testing.T) { } func TestStoreClient(t *testing.T) { - os.Clearenv() - ctx := context.Background() + ctx := t.Context() c := objectstore.ObjectStoreConfig{} err := c.SetStoreClient(ctx) require.NoError(t, err) @@ -41,7 +39,7 @@ func TestStoreClient(t *testing.T) { } func TestPingStoreByName(t *testing.T) { - ctx := context.Background() + ctx := t.Context() mocks3 := objectstoremock.NewMockS3Client(t) c := objectstore.ObjectStoreConfig{ StoreClient: mocks3, @@ -76,7 +74,7 @@ type StoreConfig struct { } func TestSetStoreClientAndPingByName(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond) defer cancel() cfg := &StoreConfig{} name := "bucket" @@ -93,7 +91,7 @@ func TestCalculateAndCompareETag(t *testing.T) { t.SkipNow() } t.SkipNow() - ctx := context.Background() + ctx := t.Context() cfg := &StoreConfig{} diff --git a/internal/serviceconfig/observability/config_test.go b/internal/serviceconfig/observability/config_test.go index eab37d10..2ca8d95c 100644 --- a/internal/serviceconfig/observability/config_test.go +++ b/internal/serviceconfig/observability/config_test.go @@ -1,7 +1,6 @@ package observability_test import ( - "context" "fmt" "testing" @@ -18,7 +17,7 @@ func TestIsOtelEnabled(t *testing.T) { } func TestSetOtel(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &observability.ObsConfig{ EnableOtel: true, diff --git a/internal/serviceconfig/observability/prometheus/prometheus_test.go b/internal/serviceconfig/observability/prometheus/prometheus_test.go index 5cd8faed..6ed32db6 100644 --- a/internal/serviceconfig/observability/prometheus/prometheus_test.go +++ b/internal/serviceconfig/observability/prometheus/prometheus_test.go @@ -37,7 +37,7 @@ func GetFreePortForTesting() (int, error) { func TestMetricsIntegration(t *testing.T) { // Create a context with cancellation for the test - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() testingPort, errorGettingPort := GetFreePortForTesting() @@ -93,7 +93,7 @@ func TestMetricsIntegration(t *testing.T) { // Ensure cleanup after test defer func() { - shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second) + shutdownCtx, shutdownCancel := context.WithTimeout(t.Context(), 5*time.Second) defer shutdownCancel() if err := metrics.Shutdown(shutdownCtx); err != nil { @@ -173,7 +173,7 @@ func TestMetricsIntegration(t *testing.T) { testingPort, errorGettingPort := GetFreePortForTesting() require.NoError(t, errorGettingPort) - cancelCtx, cancelFunc := context.WithCancel(context.Background()) + cancelCtx, cancelFunc := context.WithCancel(t.Context()) _, err := New(cancelCtx, MetricsConfig{ Namespace: "test_cancel", Port: testingPort, diff --git a/internal/serviceconfig/queue/config_test.go b/internal/serviceconfig/queue/config_test.go index 1fa9dcbe..721897fa 100644 --- a/internal/serviceconfig/queue/config_test.go +++ b/internal/serviceconfig/queue/config_test.go @@ -1,8 +1,6 @@ package queue_test import ( - "context" - "os" "testing" "queryorchestration/internal/serviceconfig/queue" @@ -21,8 +19,7 @@ func TestGetQueueClient(t *testing.T) { } func TestSetQueueClient(t *testing.T) { - os.Clearenv() - ctx := context.Background() + ctx := t.Context() c := queue.QueueConfig{} err := c.SetQueueClient(ctx) require.NoError(t, err) diff --git a/internal/serviceconfig/textract/config_test.go b/internal/serviceconfig/textract/config_test.go index 733e8988..25eab2d8 100644 --- a/internal/serviceconfig/textract/config_test.go +++ b/internal/serviceconfig/textract/config_test.go @@ -1,8 +1,6 @@ package textract_test import ( - "context" - "os" "testing" textract "queryorchestration/internal/serviceconfig/textract" @@ -20,16 +18,15 @@ func TestGetTextractClient(t *testing.T) { } func TestTextractClient(t *testing.T) { - os.Clearenv() t.Run("stndard", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() c := textract.TextractConfig{} err := c.SetTextractClient(ctx) require.NoError(t, err) assert.NotNil(t, c.TextractClient) }) t.Run("textract specific", func(t *testing.T) { - ctx := context.Background() + ctx := t.Context() c := textract.TextractConfig{ AWSTextractAccessKeyId: "not empty", AWSTextractSecretAccessKey: "not empty", @@ -43,8 +40,7 @@ func TestTextractClient(t *testing.T) { } func TestTextractClientWithProfile(t *testing.T) { - os.Clearenv() - ctx := context.Background() + ctx := t.Context() c := textract.TextractConfig{} err := c.SetTextractClientWithProfile(ctx, "") require.NoError(t, err) @@ -59,7 +55,6 @@ func TestGetTextractURL(t *testing.T) { } func TestSetTextractURL(t *testing.T) { - os.Clearenv() c := textract.TextractConfig{} c.SetTextractEndpoint("example") assert.Equal(t, "example", c.AWSEndpointUrlTextract) diff --git a/internal/test/aws.go b/internal/test/aws.go index 4fdfb7a2..3dd74fd8 100644 --- a/internal/test/aws.go +++ b/internal/test/aws.go @@ -34,14 +34,14 @@ func CreateAWSContainer(t testing.TB, cfg AWSConfigProvider) *AWSContainerConfig port, err := nat.NewPort("tcp", strconv.Itoa(awsPort)) require.NoError(t, err) - network := GetNetwork(t) - cfg.SetAWSKeyID("test") cfg.SetAWSSecretKey("test") cfg.SetAWSSessionToken("") cfg.SetAWSRegion("us-east-1") cfg.SetAWSEndpoint(fmt.Sprintf("http://%s:%d", awsAlias, awsPort)) + network := GetNetwork(t) + req := testcontainers.ContainerRequest{ Image: "localstack/localstack:4.1.0", Name: "localstack_test_queryorchestration", diff --git a/internal/test/network.go b/internal/test/network.go index e0a1c185..96997c18 100644 --- a/internal/test/network.go +++ b/internal/test/network.go @@ -39,5 +39,6 @@ func GetNetwork(t testing.TB) string { func getDockerClient(t testing.TB) *client.Client { cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) require.NoError(t, err) + return cli } diff --git a/internal/test/objectstore_test.go b/internal/test/objectstore_test.go index b27113cc..af40ca4a 100644 --- a/internal/test/objectstore_test.go +++ b/internal/test/objectstore_test.go @@ -1,7 +1,6 @@ package test import ( - "context" "strings" "testing" @@ -26,7 +25,7 @@ func TestCreateBucket(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &StoreConfig{} @@ -37,7 +36,7 @@ func TestCreateBucket(t *testing.T) { } func TestPutObject(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cfg := &StoreConfig{} diff --git a/internal/test/queue_test.go b/internal/test/queue_test.go index 95c2c866..316c0d73 100644 --- a/internal/test/queue_test.go +++ b/internal/test/queue_test.go @@ -1,7 +1,6 @@ package test import ( - "context" "regexp" "testing" @@ -27,7 +26,7 @@ func TestCreateQueue(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &TestConfig{} @@ -43,7 +42,7 @@ func TestAssertMessageWait(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &TestConfig{} @@ -68,7 +67,7 @@ func TestAssertMessageBodyWait(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &TestConfig{} @@ -90,7 +89,7 @@ func TestAssertMessageAttrWait(t *testing.T) { if testing.Short() { t.SkipNow() } - ctx := context.Background() + ctx := t.Context() cfg := &TestConfig{} diff --git a/test/queryAPI/accessory_test.go b/test/queryAPI/accessory_test.go index a980a9fe..cc68394e 100644 --- a/test/queryAPI/accessory_test.go +++ b/test/queryAPI/accessory_test.go @@ -1,7 +1,6 @@ package endtoend_test import ( - "context" "fmt" "net/http" "testing" @@ -15,7 +14,7 @@ import ( func TestQueryAPIAccessories(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{} diff --git a/test/queryAPI/client_test.go b/test/queryAPI/client_test.go index 4fb54df2..06d99558 100644 --- a/test/queryAPI/client_test.go +++ b/test/queryAPI/client_test.go @@ -1,7 +1,6 @@ package endtoend_test import ( - "context" "net/http" "testing" @@ -14,7 +13,7 @@ import ( func TestClient(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{} diff --git a/test/queryAPI/collectorservice_test.go b/test/queryAPI/collectorservice_test.go index 8071eb7e..9cb77f74 100644 --- a/test/queryAPI/collectorservice_test.go +++ b/test/queryAPI/collectorservice_test.go @@ -1,7 +1,6 @@ package endtoend_test import ( - "context" "net/http" "regexp" "testing" @@ -28,7 +27,7 @@ type Config struct { func TestCollectorService(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{} diff --git a/test/queryAPI/queryservice_test.go b/test/queryAPI/queryservice_test.go index 57e6f710..b78d7db0 100644 --- a/test/queryAPI/queryservice_test.go +++ b/test/queryAPI/queryservice_test.go @@ -1,7 +1,6 @@ package endtoend_test import ( - "context" "regexp" "testing" @@ -34,7 +33,7 @@ func TestQueryAPI(t *testing.T) { }) t.Run("create and get query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{} @@ -73,7 +72,7 @@ func TestQueryAPI(t *testing.T) { }) t.Run("update query", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{} @@ -118,7 +117,7 @@ func TestQueryAPI(t *testing.T) { }) t.Run("multiple dependent queries", func(t *testing.T) { t.Parallel() - ctx := context.Background() + ctx := t.Context() cfg := &Config{}