From d91ef1832bec2df924aaadcf182481d77a5e35d3 Mon Sep 17 00:00:00 2001 From: Michael McGuinness Date: Tue, 4 Mar 2025 15:51:03 +0000 Subject: [PATCH] Merged in feature/functestcov (pull request #84) Function Test Coverage * test * scripts --- Taskfile.yml | 3 +- api/docCleanRunner/runner_test.go | 5 +- api/docInitRunner/runner_test.go | 5 +- api/docSyncRunner/runner_test.go | 5 +- api/docTextRunner/runner_test.go | 5 +- api/jobSyncRunner/runner_test.go | 5 +- api/queryRunner/runner_test.go | 5 +- api/queryService/client_test.go | 13 ++--- api/queryService/documents_test.go | 5 +- api/queryService/job_test.go | 13 ++--- api/queryService/jobcollector_test.go | 9 +-- api/queryService/query_test.go | 22 +++---- api/querySyncRunner/runner_test.go | 5 +- api/queryVersionSyncRunner/runner_test.go | 5 +- internal/client/create_test.go | 5 +- internal/client/get_test.go | 5 +- internal/client/service_test.go | 5 +- internal/client/update_test.go | 9 +-- internal/database/repository/db_test.go | 9 +-- internal/database/repository/failtype_test.go | 41 +++++++++++++ internal/database/repository/mimetype_test.go | 41 +++++++++++++ internal/document/clean/clean_test.go | 10 ++-- internal/document/clean/create_test.go | 5 +- internal/document/get_test.go | 6 +- internal/document/init/create_test.go | 26 +++------ internal/document/list_test.go | 5 +- internal/document/sync/sync_test.go | 6 +- internal/document/text/create_test.go | 6 +- internal/document/text/extract_test.go | 6 +- internal/job/collector/create_test.go | 6 +- internal/job/collector/createprivate_test.go | 13 ++--- internal/job/collector/get_test.go | 41 +++++++++++-- internal/job/collector/service_test.go | 5 +- internal/job/collector/update/service_test.go | 5 +- internal/job/collector/update/update_test.go | 5 +- .../collector/update/updateprivate_test.go | 41 ++++--------- internal/job/create_test.go | 5 +- internal/job/get_test.go | 10 ++-- internal/job/service_test.go | 5 +- internal/job/status_test.go | 13 ++--- internal/job/sync/sync_test.go | 9 +-- internal/job/update_test.go | 5 +- internal/job/updateprivate_test.go | 13 ++--- internal/query/create_test.go | 14 ++--- internal/query/createprivate_test.go | 17 ++---- internal/query/get_test.go | 9 +-- internal/query/list_test.go | 10 ++-- internal/query/normalize_test.go | 5 +- internal/query/result/get_test.go | 5 +- internal/query/result/process_test.go | 9 +-- internal/query/result/service_test.go | 5 +- internal/query/result/set/set_test.go | 10 ++-- internal/query/result/sync/trigger_test.go | 10 ++-- internal/query/service_test.go | 5 +- internal/query/sync/service_test.go | 5 +- internal/query/sync/sync_test.go | 5 +- internal/query/test/service_test.go | 6 +- internal/query/test/test_test.go | 6 +- .../query/types/contextFull/creator_test.go | 5 +- .../query/types/contextFull/updator_test.go | 6 +- .../query/types/jsonExtractor/creator_test.go | 6 +- .../query/types/jsonExtractor/process_test.go | 14 ++--- .../query/types/jsonExtractor/updator_test.go | 5 +- internal/query/update/service_test.go | 6 +- internal/query/update/update_test.go | 6 +- internal/query/update/updateprivate_test.go | 58 +++++-------------- internal/query/versionsync/sync_test.go | 6 +- internal/serviceconfig/commonlog_test.go | 6 +- .../database/transaction_test.go | 5 +- internal/serviceconfig/logger/testlogger.go | 4 +- .../serviceconfig/logger/testlogger_test.go | 3 + .../serviceconfig/objectstore/config_test.go | 28 +++++++++ .../prometheus/prometheus_test.go | 42 ++++---------- internal/test/aws.go | 17 ++---- internal/test/container.go | 3 +- internal/test/database.go | 29 +++------- internal/test/ecosystem.go | 9 +-- internal/test/network.go | 5 +- internal/test/objectstore.go | 13 ++--- internal/test/queue.go | 9 +-- internal/test/service.go | 13 ++--- scripts/Taskfile.yml | 7 ++- scripts/database.yml | 4 +- scripts/tests.yml | 30 ++++++++-- test/process_test.go | 9 +-- 85 files changed, 446 insertions(+), 489 deletions(-) create mode 100644 internal/database/repository/failtype_test.go create mode 100644 internal/database/repository/mimetype_test.go diff --git a/Taskfile.yml b/Taskfile.yml index 24a2b550..e6a15812 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,7 +1,7 @@ --- # https://taskfile.dev -version: '3' +version: "3" includes: lib: @@ -10,3 +10,4 @@ includes: vars: IMAGE_NAME: queryorchestration COVERAGE_THRESHOLD: 80 + FUNCTION_COVERAGE_THRESHOLD: 10 diff --git a/api/docCleanRunner/runner_test.go b/api/docCleanRunner/runner_test.go index bd740fc0..5f9f63c7 100644 --- a/api/docCleanRunner/runner_test.go +++ b/api/docCleanRunner/runner_test.go @@ -27,6 +27,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type DocCleanConfig struct { @@ -39,9 +40,7 @@ func TestDocCleanRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocCleanConfig{} cfg.DBPool = pool diff --git a/api/docInitRunner/runner_test.go b/api/docInitRunner/runner_test.go index 65d677ae..be4994ec 100644 --- a/api/docInitRunner/runner_test.go +++ b/api/docInitRunner/runner_test.go @@ -22,6 +22,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type DocInitConfig struct { @@ -33,9 +34,7 @@ func TestDocInitRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool diff --git a/api/docSyncRunner/runner_test.go b/api/docSyncRunner/runner_test.go index a9f5a5e3..c83d37a2 100644 --- a/api/docSyncRunner/runner_test.go +++ b/api/docSyncRunner/runner_test.go @@ -19,6 +19,7 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type DocSyncConfig struct { @@ -30,9 +31,7 @@ func TestDocInitRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocSyncConfig{} cfg.DBPool = pool diff --git a/api/docTextRunner/runner_test.go b/api/docTextRunner/runner_test.go index 79519738..cd81313e 100644 --- a/api/docTextRunner/runner_test.go +++ b/api/docTextRunner/runner_test.go @@ -22,6 +22,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type DocTextConfig struct { @@ -33,9 +34,7 @@ func TestDocCleanRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocTextConfig{} cfg.DBPool = pool diff --git a/api/jobSyncRunner/runner_test.go b/api/jobSyncRunner/runner_test.go index dc31ae0d..bb9eea04 100644 --- a/api/jobSyncRunner/runner_test.go +++ b/api/jobSyncRunner/runner_test.go @@ -20,6 +20,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type JobSyncConfig struct { @@ -31,9 +32,7 @@ func TestQueryRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &JobSyncConfig{} cfg.DBPool = pool diff --git a/api/queryRunner/runner_test.go b/api/queryRunner/runner_test.go index 56c379b2..7840d659 100644 --- a/api/queryRunner/runner_test.go +++ b/api/queryRunner/runner_test.go @@ -24,6 +24,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type QueryConfig struct { @@ -35,9 +36,7 @@ func TestQueryRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryConfig{} cfg.DBPool = pool diff --git a/api/queryService/client_test.go b/api/queryService/client_test.go index cea3f26c..68fa741e 100644 --- a/api/queryService/client_test.go +++ b/api/queryService/client_test.go @@ -18,13 +18,12 @@ import ( "github.com/labstack/echo/v4" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreateClient(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool @@ -61,9 +60,7 @@ func TestCreateClient(t *testing.T) { func TestGetClient(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool @@ -103,9 +100,7 @@ func TestGetClient(t *testing.T) { func TestUpdateClient(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool diff --git a/api/queryService/documents_test.go b/api/queryService/documents_test.go index 5bcd1bee..ff1f8d37 100644 --- a/api/queryService/documents_test.go +++ b/api/queryService/documents_test.go @@ -19,13 +19,12 @@ import ( "github.com/labstack/echo/v4" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestListDocumentsByJobId(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &struct { serviceconfig.BaseConfig jobsync.JobSyncConfig diff --git a/api/queryService/job_test.go b/api/queryService/job_test.go index 490100b1..94bf313e 100644 --- a/api/queryService/job_test.go +++ b/api/queryService/job_test.go @@ -23,13 +23,12 @@ import ( "github.com/labstack/echo/v4" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreateJob(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool @@ -79,9 +78,7 @@ func TestCreateJob(t *testing.T) { func TestGetJob(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -134,9 +131,7 @@ func TestGetJob(t *testing.T) { func TestUpdateJob(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/api/queryService/jobcollector_test.go b/api/queryService/jobcollector_test.go index 0aa9f904..317e79db 100644 --- a/api/queryService/jobcollector_test.go +++ b/api/queryService/jobcollector_test.go @@ -27,13 +27,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) func TestUpdateJobCollector(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &struct { serviceconfig.BaseConfig jobsync.JobSyncConfig @@ -122,9 +121,7 @@ func TestUpdateJobCollector(t *testing.T) { func TestGetJobCollectorByJobId(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/api/queryService/query_test.go b/api/queryService/query_test.go index 649e9135..c78cba96 100644 --- a/api/queryService/query_test.go +++ b/api/queryService/query_test.go @@ -22,6 +22,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/go-playground/validator/v10" "github.com/google/uuid" @@ -35,9 +37,7 @@ import ( func TestCreateQuery(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -81,9 +81,7 @@ func TestCreateQuery(t *testing.T) { func TestListQueries(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -124,9 +122,7 @@ func TestListQueries(t *testing.T) { func TestGetQuery(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -166,9 +162,7 @@ func TestGetQuery(t *testing.T) { func TestUpdateQuery(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &struct { serviceconfig.BaseConfig queryversionsync.QueryVersionSyncConfig @@ -229,9 +223,7 @@ func TestUpdateQuery(t *testing.T) { func TestTestQuery(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/api/querySyncRunner/runner_test.go b/api/querySyncRunner/runner_test.go index 7a35fabd..f9363576 100644 --- a/api/querySyncRunner/runner_test.go +++ b/api/querySyncRunner/runner_test.go @@ -21,6 +21,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type QuerySyncConfig struct { @@ -32,9 +33,7 @@ func TestQueryRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QuerySyncConfig{} cfg.DBPool = pool diff --git a/api/queryVersionSyncRunner/runner_test.go b/api/queryVersionSyncRunner/runner_test.go index 965ff3c1..189430e4 100644 --- a/api/queryVersionSyncRunner/runner_test.go +++ b/api/queryVersionSyncRunner/runner_test.go @@ -20,6 +20,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type QuerySyncConfig struct { @@ -31,9 +32,7 @@ func TestQueryRunner(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QuerySyncConfig{} cfg.DBPool = pool diff --git a/internal/client/create_test.go b/internal/client/create_test.go index efc7cdde..38ed75d8 100644 --- a/internal/client/create_test.go +++ b/internal/client/create_test.go @@ -11,15 +11,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/client/get_test.go b/internal/client/get_test.go index 639c31d1..f9e7380f 100644 --- a/internal/client/get_test.go +++ b/internal/client/get_test.go @@ -12,15 +12,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/client/service_test.go b/internal/client/service_test.go index c08f2165..4633a01f 100644 --- a/internal/client/service_test.go +++ b/internal/client/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/client/update_test.go b/internal/client/update_test.go index 090340bc..d530cdcd 100644 --- a/internal/client/update_test.go +++ b/internal/client/update_test.go @@ -10,15 +10,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -115,9 +114,7 @@ func TestSubmitUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/database/repository/db_test.go b/internal/database/repository/db_test.go index b51babe3..6c445054 100644 --- a/internal/database/repository/db_test.go +++ b/internal/database/repository/db_test.go @@ -8,13 +8,12 @@ import ( "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestQueriesNew(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) queries := repository.New(pool) assert.NotNil(t, queries) @@ -24,9 +23,7 @@ func TestQueriesWithTx(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) queries := repository.New(pool) assert.NotNil(t, queries) diff --git a/internal/database/repository/failtype_test.go b/internal/database/repository/failtype_test.go new file mode 100644 index 00000000..b42fca58 --- /dev/null +++ b/internal/database/repository/failtype_test.go @@ -0,0 +1,41 @@ +package repository_test + +import ( + "fmt" + "queryorchestration/internal/database/repository" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFailTypeScan(t *testing.T) { + qType := repository.Cleanfailtype(fmt.Sprint(0)) + + stringType := "invalid_mimetype" + err := qType.Scan(stringType) + assert.NoError(t, err) +} + +func TestNullFailTypeScan(t *testing.T) { + qType := repository.NullCleanfailtype{} + + stringType := "invalid_mimetype" + err := qType.Scan(stringType) + assert.NoError(t, err) +} + +func TestNullFailTypeValue(t *testing.T) { + qType := repository.NullCleanfailtype{} + + stringType := "invalid_mimetype" + err := qType.Scan(stringType) + assert.NoError(t, err) + + val, err := qType.Value() + assert.NoError(t, err) + assert.Equal(t, stringType, val) +} + +func TestFailTypeValid(t *testing.T) { + assert.True(t, repository.CleanfailtypeInvalidMimetype.Valid()) +} diff --git a/internal/database/repository/mimetype_test.go b/internal/database/repository/mimetype_test.go new file mode 100644 index 00000000..3a7bf0f0 --- /dev/null +++ b/internal/database/repository/mimetype_test.go @@ -0,0 +1,41 @@ +package repository_test + +import ( + "fmt" + "queryorchestration/internal/database/repository" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMimeTypeScan(t *testing.T) { + qType := repository.Cleanmimetype(fmt.Sprint(0)) + + stringType := "application/pdf" + err := qType.Scan(stringType) + assert.NoError(t, err) +} + +func TestNullMimeTypeScan(t *testing.T) { + qType := repository.NullCleanmimetype{} + + stringType := "application/pdf" + err := qType.Scan(stringType) + assert.NoError(t, err) +} + +func TestNullMimeTypeValue(t *testing.T) { + qType := repository.NullCleanmimetype{} + + stringType := "application/pdf" + err := qType.Scan(stringType) + assert.NoError(t, err) + + val, err := qType.Value() + assert.NoError(t, err) + assert.Equal(t, stringType, val) +} + +func TestMimeTypeValid(t *testing.T) { + assert.True(t, repository.CleanmimetypeApplicationPdf.Valid()) +} diff --git a/internal/document/clean/clean_test.go b/internal/document/clean/clean_test.go index 58e6d82e..da5b199b 100644 --- a/internal/document/clean/clean_test.go +++ b/internal/document/clean/clean_test.go @@ -11,6 +11,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -21,9 +23,7 @@ import ( func TestClean(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocCleanConfig{} cfg.DBPool = pool @@ -166,9 +166,7 @@ func TestExecuteCleanTasks(t *testing.T) { func TestStoreClean(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocCleanConfig{} cfg.DBPool = pool diff --git a/internal/document/clean/create_test.go b/internal/document/clean/create_test.go index fe8376b5..9edead26 100644 --- a/internal/document/clean/create_test.go +++ b/internal/document/clean/create_test.go @@ -22,6 +22,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type DocCleanConfig struct { @@ -33,9 +34,7 @@ type DocCleanConfig struct { func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/document/get_test.go b/internal/document/get_test.go index 46f69516..3cabcd8c 100644 --- a/internal/document/get_test.go +++ b/internal/document/get_test.go @@ -8,6 +8,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" @@ -17,9 +19,7 @@ func TestGet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/document/init/create_test.go b/internal/document/init/create_test.go index 0ea39903..14fdc856 100644 --- a/internal/document/init/create_test.go +++ b/internal/document/init/create_test.go @@ -11,6 +11,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -22,9 +24,7 @@ func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -97,9 +97,7 @@ func TestGetCreateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -136,9 +134,7 @@ func TestGetCreateParamsExisting(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -179,9 +175,7 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -211,9 +205,7 @@ func TestSubmitCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -253,9 +245,7 @@ func TestSubmitCreateExists(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocInitConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/document/list_test.go b/internal/document/list_test.go index 91c6bd84..3d5a448f 100644 --- a/internal/document/list_test.go +++ b/internal/document/list_test.go @@ -11,15 +11,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestListByJobId(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/document/sync/sync_test.go b/internal/document/sync/sync_test.go index c68c96c3..420a117f 100644 --- a/internal/document/sync/sync_test.go +++ b/internal/document/sync/sync_test.go @@ -12,6 +12,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -23,9 +25,7 @@ func TestSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/document/text/create_test.go b/internal/document/text/create_test.go index f4a60ede..b7ac4057 100644 --- a/internal/document/text/create_test.go +++ b/internal/document/text/create_test.go @@ -12,6 +12,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -27,9 +29,7 @@ type DocTextConfig struct { func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) mockSQS := queuemock.NewMockSQSClient(t) diff --git a/internal/document/text/extract_test.go b/internal/document/text/extract_test.go index b774da9c..955b0b22 100644 --- a/internal/document/text/extract_test.go +++ b/internal/document/text/extract_test.go @@ -8,6 +8,8 @@ import ( textversion "queryorchestration/internal/document/text/version" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" @@ -16,9 +18,7 @@ import ( func TestExtract(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &DocTextConfig{} cfg.DBPool = pool diff --git a/internal/job/collector/create_test.go b/internal/job/collector/create_test.go index 2c4fc125..0af531af 100644 --- a/internal/job/collector/create_test.go +++ b/internal/job/collector/create_test.go @@ -8,6 +8,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v3" @@ -18,9 +20,7 @@ func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/collector/createprivate_test.go b/internal/job/collector/createprivate_test.go index 906997c6..7d6d1655 100644 --- a/internal/job/collector/createprivate_test.go +++ b/internal/job/collector/createprivate_test.go @@ -12,15 +12,14 @@ import ( "github.com/jackc/pgx/v5/pgtype" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetCreateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -67,9 +66,7 @@ func TestSubmitCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -113,9 +110,7 @@ func TestNormalizeFieldsToDB(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/collector/get_test.go b/internal/job/collector/get_test.go index 968dc1e3..a25a9c1b 100644 --- a/internal/job/collector/get_test.go +++ b/internal/job/collector/get_test.go @@ -6,21 +6,21 @@ import ( "queryorchestration/internal/database" "queryorchestration/internal/database/repository" "queryorchestration/internal/job/collector" + resultprocessor "queryorchestration/internal/query/result/processor" "queryorchestration/internal/serviceconfig" "testing" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -53,9 +53,7 @@ func TestGetByJobID(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -83,3 +81,34 @@ func TestGetByJobID(t *testing.T) { assert.NoError(t, err) assert.EqualExportedValues(t, ogc, *coll) } + +func TestListQueries(t *testing.T) { + ctx := context.Background() + + pool, err := pgxmock.NewPool() + require.NoError(t, err) + cfg := &serviceconfig.BaseConfig{} + cfg.DBPool = pool + cfg.DBQueries = repository.New(pool) + + svc := collector.New(cfg, &collector.Services{}) + + jobId := uuid.New() + ogc := []*resultprocessor.Query{ + { + ID: uuid.New(), + Type: resultprocessor.TypeContextFull, + Version: 2, + }, + } + + pool.ExpectQuery("name: ListCollectorQueries :many").WithArgs(database.MustToDBUUID(jobId)). + WillReturnRows( + pgxmock.NewRows([]string{"jobId", "queryId", "type", "queryVersion", "requiredIds"}). + AddRow(database.MustToDBUUID(jobId), database.MustToDBUUID(ogc[0].ID), repository.QuerytypeContextFull, int32(2), nil), + ) + + qs, err := svc.ListQueries(ctx, jobId) + assert.NoError(t, err) + assert.EqualExportedValues(t, ogc, qs) +} diff --git a/internal/job/collector/service_test.go b/internal/job/collector/service_test.go index f442ca47..799d530e 100644 --- a/internal/job/collector/service_test.go +++ b/internal/job/collector/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/collector/update/service_test.go b/internal/job/collector/update/service_test.go index 09f1a4a7..40454656 100644 --- a/internal/job/collector/update/service_test.go +++ b/internal/job/collector/update/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/collector/update/update_test.go b/internal/job/collector/update/update_test.go index 18dc8fa6..ad7033ef 100644 --- a/internal/job/collector/update/update_test.go +++ b/internal/job/collector/update/update_test.go @@ -18,6 +18,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type CollectorUpdateConfig struct { @@ -29,9 +30,7 @@ func TestUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/collector/update/updateprivate_test.go b/internal/job/collector/update/updateprivate_test.go index 8a04e31c..c84aba03 100644 --- a/internal/job/collector/update/updateprivate_test.go +++ b/internal/job/collector/update/updateprivate_test.go @@ -20,6 +20,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type CollectorUpdateConfig struct { @@ -32,9 +33,7 @@ func TestGetUpdateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -90,9 +89,7 @@ func TestGetUpdateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -114,9 +111,7 @@ func TestGetUpdateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -143,9 +138,7 @@ func TestGetUpdateParams(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -177,9 +170,7 @@ func TestSubmitUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -247,9 +238,7 @@ func TestSubmitUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -543,9 +532,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -578,9 +565,7 @@ func TestNormalizeUpdateFieldsToDB(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -633,9 +618,7 @@ func TestInformUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -668,9 +651,7 @@ func TestInformUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &CollectorUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/create_test.go b/internal/job/create_test.go index 50d174c7..c9a2afc2 100644 --- a/internal/job/create_test.go +++ b/internal/job/create_test.go @@ -13,15 +13,14 @@ import ( "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/get_test.go b/internal/job/get_test.go index e92daee1..3e88bd5b 100644 --- a/internal/job/get_test.go +++ b/internal/job/get_test.go @@ -10,6 +10,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" @@ -19,9 +21,7 @@ func TestGet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -78,9 +78,7 @@ func TestGetWithStatus(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/service_test.go b/internal/job/service_test.go index 8715148d..7c4c1d0e 100644 --- a/internal/job/service_test.go +++ b/internal/job/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/status_test.go b/internal/job/status_test.go index ad2b36a2..194f647c 100644 --- a/internal/job/status_test.go +++ b/internal/job/status_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetStatus(t *testing.T) { @@ -19,9 +20,7 @@ func TestGetStatus(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -43,9 +42,7 @@ func TestGetStatus(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -67,9 +64,7 @@ func TestGetStatus(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/sync/sync_test.go b/internal/job/sync/sync_test.go index 94430ede..222d66c9 100644 --- a/internal/job/sync/sync_test.go +++ b/internal/job/sync/sync_test.go @@ -16,6 +16,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type JobSyncConfig struct { @@ -28,9 +29,7 @@ func TestTrigger(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &JobSyncConfig{} cfg.DBPool = pool @@ -91,9 +90,7 @@ func TestTrigger(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &JobSyncConfig{} cfg.DBPool = pool diff --git a/internal/job/update_test.go b/internal/job/update_test.go index 6e54200b..23bf76dd 100644 --- a/internal/job/update_test.go +++ b/internal/job/update_test.go @@ -12,15 +12,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/job/updateprivate_test.go b/internal/job/updateprivate_test.go index aa37a86e..33e83857 100644 --- a/internal/job/updateprivate_test.go +++ b/internal/job/updateprivate_test.go @@ -11,15 +11,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNormalizeCanSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -95,9 +94,7 @@ func TestNormalizeUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -128,9 +125,7 @@ func TestSubmitUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/create_test.go b/internal/query/create_test.go index 30f44ed3..cc369a7a 100644 --- a/internal/query/create_test.go +++ b/internal/query/create_test.go @@ -10,6 +10,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v3" @@ -20,9 +22,7 @@ func TestCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -78,9 +78,7 @@ func TestCreateMinimal(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -119,9 +117,7 @@ func TestCreateRollback(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/createprivate_test.go b/internal/query/createprivate_test.go index c2c1c582..9b4f400c 100644 --- a/internal/query/createprivate_test.go +++ b/internal/query/createprivate_test.go @@ -12,13 +12,12 @@ import ( "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetCreator(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -78,9 +77,7 @@ func TestSubmitCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -132,9 +129,7 @@ func TestSubmitCreateNoReqsOrConfig(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -173,9 +168,7 @@ func TestNormalizeCreate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/get_test.go b/internal/query/get_test.go index 28122440..28739390 100644 --- a/internal/query/get_test.go +++ b/internal/query/get_test.go @@ -12,15 +12,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -55,9 +54,7 @@ func TestGetWithVersion(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/list_test.go b/internal/query/list_test.go index 43858340..46e774af 100644 --- a/internal/query/list_test.go +++ b/internal/query/list_test.go @@ -12,6 +12,8 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) @@ -19,9 +21,7 @@ func TestList(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -56,9 +56,7 @@ func TestListById(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/normalize_test.go b/internal/query/normalize_test.go index 299c4d3b..b5304d94 100644 --- a/internal/query/normalize_test.go +++ b/internal/query/normalize_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNormalizeConfig(t *testing.T) { @@ -72,9 +73,7 @@ func TestNormalizeQueryIDs(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/result/get_test.go b/internal/query/result/get_test.go index d03ca62e..43eb1df6 100644 --- a/internal/query/result/get_test.go +++ b/internal/query/result/get_test.go @@ -13,6 +13,7 @@ import ( "github.com/jackc/pgx/v5/pgtype" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetValueByType(t *testing.T) { @@ -32,9 +33,7 @@ func TestGetValueWithVersion(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/result/process_test.go b/internal/query/result/process_test.go index 530b2184..853ab65b 100644 --- a/internal/query/result/process_test.go +++ b/internal/query/result/process_test.go @@ -13,15 +13,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestProcess(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -71,9 +70,7 @@ func TestListRequiredValue(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/result/service_test.go b/internal/query/result/service_test.go index 82ca66ed..1f07dc1c 100644 --- a/internal/query/result/service_test.go +++ b/internal/query/result/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/result/set/set_test.go b/internal/query/result/set/set_test.go index b148bd30..0120083c 100644 --- a/internal/query/result/set/set_test.go +++ b/internal/query/result/set/set_test.go @@ -14,6 +14,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -30,9 +32,7 @@ func TestSet(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &ResultSetConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -128,9 +128,7 @@ func TestInformQueryDependents(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &ResultSetConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/result/sync/trigger_test.go b/internal/query/result/sync/trigger_test.go index 2268d2ae..9d7cb90f 100644 --- a/internal/query/result/sync/trigger_test.go +++ b/internal/query/result/sync/trigger_test.go @@ -9,6 +9,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -25,9 +27,7 @@ func TestTriggerSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &ResultSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -62,9 +62,7 @@ func TestTriggerMultiSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &ResultSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/service_test.go b/internal/query/service_test.go index b75fe895..4dac02fe 100644 --- a/internal/query/service_test.go +++ b/internal/query/service_test.go @@ -8,13 +8,12 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/sync/service_test.go b/internal/query/sync/service_test.go index 781fbf9c..8c47e2ad 100644 --- a/internal/query/sync/service_test.go +++ b/internal/query/sync/service_test.go @@ -9,6 +9,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type QuerySyncConfig struct { @@ -18,9 +19,7 @@ type QuerySyncConfig struct { func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QuerySyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/sync/sync_test.go b/internal/query/sync/sync_test.go index c48ef6a8..051ed24f 100644 --- a/internal/query/sync/sync_test.go +++ b/internal/query/sync/sync_test.go @@ -16,6 +16,7 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" ) type QuerySyncConfig struct { @@ -26,9 +27,7 @@ type QuerySyncConfig struct { func TestSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QuerySyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/test/service_test.go b/internal/query/test/service_test.go index df308182..4bdae1a2 100644 --- a/internal/query/test/service_test.go +++ b/internal/query/test/service_test.go @@ -6,15 +6,15 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/test/test_test.go b/internal/query/test/test_test.go index 0082b133..bc77d47b 100644 --- a/internal/query/test/test_test.go +++ b/internal/query/test/test_test.go @@ -14,6 +14,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/pashagolub/pgxmock/v3" @@ -24,9 +26,7 @@ func TestTest(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/types/contextFull/creator_test.go b/internal/query/types/contextFull/creator_test.go index 35b0adcf..c9be9c9e 100644 --- a/internal/query/types/contextFull/creator_test.go +++ b/internal/query/types/contextFull/creator_test.go @@ -10,15 +10,14 @@ import ( "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreatorValidate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/types/contextFull/updator_test.go b/internal/query/types/contextFull/updator_test.go index 6d59a6c1..0950f635 100644 --- a/internal/query/types/contextFull/updator_test.go +++ b/internal/query/types/contextFull/updator_test.go @@ -9,6 +9,8 @@ import ( "testing" "github.com/google/uuid" + "github.com/stretchr/testify/require" + "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" ) @@ -17,9 +19,7 @@ func TestUpdatorValidate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/types/jsonExtractor/creator_test.go b/internal/query/types/jsonExtractor/creator_test.go index 5787eaea..09dc5c52 100644 --- a/internal/query/types/jsonExtractor/creator_test.go +++ b/internal/query/types/jsonExtractor/creator_test.go @@ -8,6 +8,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" ) @@ -16,9 +18,7 @@ func TestCreatorValidate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/types/jsonExtractor/process_test.go b/internal/query/types/jsonExtractor/process_test.go index 0692c46c..081a4227 100644 --- a/internal/query/types/jsonExtractor/process_test.go +++ b/internal/query/types/jsonExtractor/process_test.go @@ -11,6 +11,8 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" @@ -20,9 +22,7 @@ func TestJSONProcess(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -88,9 +88,7 @@ func TestJSONProcessJSON(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -171,9 +169,7 @@ func TestJSONProcessResults(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/types/jsonExtractor/updator_test.go b/internal/query/types/jsonExtractor/updator_test.go index e3154b44..ea4004df 100644 --- a/internal/query/types/jsonExtractor/updator_test.go +++ b/internal/query/types/jsonExtractor/updator_test.go @@ -11,15 +11,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUpdatorValidate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/update/service_test.go b/internal/query/update/service_test.go index 941f54f9..6f09ef96 100644 --- a/internal/query/update/service_test.go +++ b/internal/query/update/service_test.go @@ -6,15 +6,15 @@ import ( "queryorchestration/internal/serviceconfig" "testing" + "github.com/stretchr/testify/require" + "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" ) func TestService(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/update/update_test.go b/internal/query/update/update_test.go index c2177a8c..eb1d2e9d 100644 --- a/internal/query/update/update_test.go +++ b/internal/query/update/update_test.go @@ -13,6 +13,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/jackc/pgx/v5" @@ -31,9 +33,7 @@ func TestUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/update/updateprivate_test.go b/internal/query/update/updateprivate_test.go index c60e6a86..6ae360f5 100644 --- a/internal/query/update/updateprivate_test.go +++ b/internal/query/update/updateprivate_test.go @@ -13,6 +13,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/jackc/pgx/v5" @@ -28,9 +30,7 @@ type QueryUpdateConfig struct { func TestGetUpdator(t *testing.T) { pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -57,9 +57,7 @@ func TestSubmitUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -110,9 +108,7 @@ func TestSubmitUpdateRollback(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -147,9 +143,7 @@ func TestSubmitUpdateRequiredQueries(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -201,9 +195,7 @@ func TestSubmitUpdateRequiredQueries(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -243,9 +235,7 @@ func TestSubmitUpdateActiveVersion(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -291,9 +281,7 @@ func TestNormalizeUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -330,9 +318,7 @@ func TestNormalizeUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -357,9 +343,7 @@ func TestNormalizeUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -386,9 +370,7 @@ func TestNormalizeUpdate(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -417,9 +399,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -447,9 +427,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -479,9 +457,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) @@ -514,9 +490,7 @@ func TestNormalizeUpdateRequiredQueryIDs(t *testing.T) { t.Run("same update and current", func(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryUpdateConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/query/versionsync/sync_test.go b/internal/query/versionsync/sync_test.go index c6d845c1..ef7650a6 100644 --- a/internal/query/versionsync/sync_test.go +++ b/internal/query/versionsync/sync_test.go @@ -10,6 +10,8 @@ import ( queuemock "queryorchestration/mocks/queue" "testing" + "github.com/stretchr/testify/require" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" @@ -25,9 +27,7 @@ type QueryVersionSyncConfig struct { func TestSync(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &QueryVersionSyncConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/serviceconfig/commonlog_test.go b/internal/serviceconfig/commonlog_test.go index 367ceb5f..5b118c72 100644 --- a/internal/serviceconfig/commonlog_test.go +++ b/internal/serviceconfig/commonlog_test.go @@ -7,6 +7,8 @@ import ( "queryorchestration/internal/serviceconfig" "strings" "testing" + + "github.com/stretchr/testify/require" ) // TestPrintConfigRecursive tests the PrintConfigRecursive function as a blackbox test. @@ -42,9 +44,7 @@ func TestPrintConfigRecursive(t *testing.T) { // Use BaseConfig instead of initializeConfigTestStruct cfg := &serviceconfig.BaseConfig{} err := serviceconfig.InitializeConfig(cfg) - if err != nil { - t.Fatalf("Error initializing config: %v", err) - } + require.NoError(t, err) // Set logger after initialization cfg.Logger = testLogger diff --git a/internal/serviceconfig/database/transaction_test.go b/internal/serviceconfig/database/transaction_test.go index 90d5ce57..52477216 100644 --- a/internal/serviceconfig/database/transaction_test.go +++ b/internal/serviceconfig/database/transaction_test.go @@ -10,15 +10,14 @@ import ( "github.com/google/uuid" "github.com/pashagolub/pgxmock/v3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestExecuteTransaction(t *testing.T) { ctx := context.Background() pool, err := pgxmock.NewPool() - if err != nil { - t.Fatalf("failed to open pgxmock database: %v", err) - } + require.NoError(t, err) cfg := &serviceconfig.BaseConfig{} cfg.DBPool = pool cfg.DBQueries = repository.New(pool) diff --git a/internal/serviceconfig/logger/testlogger.go b/internal/serviceconfig/logger/testlogger.go index 10d4c5ba..27166f73 100644 --- a/internal/serviceconfig/logger/testlogger.go +++ b/internal/serviceconfig/logger/testlogger.go @@ -8,11 +8,11 @@ import ( type TestLogger struct { T *testing.T - Logs []map[string]interface{} + Logs []map[string]any } func (l *TestLogger) Handle(ctx context.Context, r slog.Record) error { - attrs := make(map[string]interface{}) + attrs := make(map[string]any) r.Attrs(func(a slog.Attr) bool { attrs[a.Key] = a.Value.Any() return true diff --git a/internal/serviceconfig/logger/testlogger_test.go b/internal/serviceconfig/logger/testlogger_test.go index e7819580..a7b798e7 100644 --- a/internal/serviceconfig/logger/testlogger_test.go +++ b/internal/serviceconfig/logger/testlogger_test.go @@ -22,4 +22,7 @@ func TestTestLogger(t *testing.T) { assert.Equal(t, "second", tl.Logs[1]["field"]) assert.Equal(t, "warn", tl.Logs[2]["field"]) assert.Equal(t, "error", tl.Logs[3]["field"]) + + assert.NotNil(t, logger.Handler().WithAttrs([]slog.Attr{})) + assert.NotNil(t, logger.Handler().WithGroup("group")) } diff --git a/internal/serviceconfig/objectstore/config_test.go b/internal/serviceconfig/objectstore/config_test.go index ac4f0782..57c05aca 100644 --- a/internal/serviceconfig/objectstore/config_test.go +++ b/internal/serviceconfig/objectstore/config_test.go @@ -2,10 +2,13 @@ package objectstore_test import ( "context" + "errors" "os" + "queryorchestration/internal/serviceconfig" objectstore "queryorchestration/internal/serviceconfig/objectstore" objectstoremock "queryorchestration/mocks/objectstore" "testing" + "time" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/stretchr/testify/assert" @@ -49,3 +52,28 @@ func TestPingStoreByName(t *testing.T) { err := c.PingStoreByName(ctx, name) assert.NoError(t, err) } + +func TestGetS3Client(t *testing.T) { + c := objectstore.ObjectStoreConfig{} + assert.Empty(t, c.GetS3Endpoint()) + c.AWSEndpointUrlS3 = "s3_endpoint" + assert.Equal(t, "s3_endpoint", c.GetS3Endpoint()) +} + +type StoreConfig struct { + serviceconfig.BaseConfig + objectstore.ObjectStoreConfig +} + +func TestSetStoreClientAndPingByName(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() + cfg := &StoreConfig{} + name := "bucket" + + err := cfg.SetStoreClientAndPingByName(ctx, name) + + if !errors.Is(err, context.DeadlineExceeded) { + t.Errorf("Expected timeout error, got: %v", err) + } +} diff --git a/internal/serviceconfig/observability/prometheus/prometheus_test.go b/internal/serviceconfig/observability/prometheus/prometheus_test.go index 2069d090..067fc117 100644 --- a/internal/serviceconfig/observability/prometheus/prometheus_test.go +++ b/internal/serviceconfig/observability/prometheus/prometheus_test.go @@ -9,6 +9,8 @@ import ( "strings" "testing" "time" + + "github.com/stretchr/testify/require" ) func GetFreePortForTesting() (int, error) { @@ -34,9 +36,7 @@ func TestMetricsIntegration(t *testing.T) { defer cancel() testingPort, errorGettingPort := GetFreePortForTesting() - if errorGettingPort != nil { - t.Fatalf("Failed to get a free port for testing: %v", errorGettingPort) - } + require.NoError(t, errorGettingPort) // Step 1: Define our test metrics configuration config := MetricsConfig{ @@ -84,9 +84,7 @@ func TestMetricsIntegration(t *testing.T) { // Step 2: Create new metrics instance with context metrics, err := New(ctx, config) - if err != nil { - t.Fatalf("Failed to create metrics: %v", err) - } + require.NoError(t, err) // Ensure cleanup after test defer func() { @@ -104,33 +102,25 @@ func TestMetricsIntegration(t *testing.T) { "type": "user_login", "status": "success", }) - if err != nil { - t.Fatalf("Failed to record counter metric: %v", err) - } + require.NoError(t, err) // Record a gauge metric err = metrics.RecordMetric("queue_size", 15, map[string]string{ "queue_name": "default", }) - if err != nil { - t.Fatalf("Failed to record gauge metric: %v", err) - } + require.NoError(t, err) // Record a histogram metric err = metrics.RecordMetric("response_time_seconds", 0.7, map[string]string{ "endpoint": "/api/users", }) - if err != nil { - t.Fatalf("Failed to record histogram metric: %v", err) - } + require.NoError(t, err) // Record a summary metric err = metrics.RecordMetric("request_size_bytes", 1024, map[string]string{ "method": "POST", }) - if err != nil { - t.Fatalf("Failed to record summary metric: %v", err) - } + require.NoError(t, err) // Step 4: Wait for HTTP server to start // Give the server a moment to start up @@ -139,16 +129,12 @@ func TestMetricsIntegration(t *testing.T) { // Step 5: Fetch metrics from the HTTP endpoint URLForMetrics := fmt.Sprintf("http://localhost:%d/metrics", testingPort) resp, err := http.Get(URLForMetrics) - if err != nil { - t.Fatalf("Failed to fetch metrics: %v", err) - } + require.NoError(t, err) defer resp.Body.Close() // Read the response body body, err := io.ReadAll(resp.Body) - if err != nil { - t.Fatalf("Failed to read response body: %v", err) - } + require.NoError(t, err) metricsOutput := string(body) // if needed for debugging. @@ -180,9 +166,7 @@ func TestMetricsIntegration(t *testing.T) { t.Run("Context cancellation", func(t *testing.T) { // Create a new metrics instance with a separate context testingPort, errorGettingPort := GetFreePortForTesting() - if errorGettingPort != nil { - t.Fatalf("Failed to get a free port for testing: %v", errorGettingPort) - } + require.NoError(t, errorGettingPort) cancelCtx, cancelFunc := context.WithCancel(context.Background()) _, err := New(cancelCtx, MetricsConfig{ @@ -190,9 +174,7 @@ func TestMetricsIntegration(t *testing.T) { Port: testingPort, ServeHttp: true, }) - if err != nil { - t.Fatalf("Failed to create metrics for cancellation test: %v", err) - } + require.NoError(t, err) // Wait for server to start time.Sleep(time.Second) diff --git a/internal/test/aws.go b/internal/test/aws.go index 995f83e1..b6ad1a16 100644 --- a/internal/test/aws.go +++ b/internal/test/aws.go @@ -10,6 +10,7 @@ import ( "time" "github.com/docker/go-connections/nat" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) @@ -29,9 +30,7 @@ func CreateAWSContainer(t testing.TB, ctx context.Context, cfg *CreateAWSConfig) alias := "localstack" port, err := nat.NewPort("tcp", "4566") - if err != nil { - t.Fatalf("Failed to create port: %v", err) - } + require.NoError(t, err) req := testcontainers.ContainerRequest{ Image: "localstack/localstack:4.1.0", @@ -77,18 +76,12 @@ func CreateAWSContainer(t testing.TB, ctx context.Context, cfg *CreateAWSConfig) ContainerRequest: req, Started: true, }) - if err != nil { - t.Fatalf("Failed to start container: %v", err) - } + require.NoError(t, err) host, err := container.Host(ctx) - if err != nil { - t.Fatalf("Failed to extract host: %v", err) - } + require.NoError(t, err) mappedPort, err := container.MappedPort(ctx, port) - if err != nil { - t.Fatalf("Failed to extract port: %v", err) - } + require.NoError(t, err) extEndpoint := fmt.Sprintf("http://%s:%s", host, mappedPort.Port()) t.Setenv("AWS_ENDPOINT_URL", extEndpoint) diff --git a/internal/test/container.go b/internal/test/container.go index 9b43c603..8b79a4b8 100644 --- a/internal/test/container.go +++ b/internal/test/container.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/go-connections/nat" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) @@ -81,7 +82,7 @@ func createContainer(t testing.TB, ctx context.Context, cfg *containerConfig) (t slog.Error(line) } - t.Fatalf("Failed to start container: %v", err) + require.NoError(t, err) } return container, func() { diff --git a/internal/test/database.go b/internal/test/database.go index 823b6953..4bb581c9 100644 --- a/internal/test/database.go +++ b/internal/test/database.go @@ -10,6 +10,7 @@ import ( "time" "github.com/docker/go-connections/nat" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) @@ -24,9 +25,7 @@ func CreateDB(t testing.TB, ctx context.Context, cfg *CreateDatabaseConfig) (tes alias := "postgres" port, err := nat.NewPort("tcp", "5432") - if err != nil { - t.Fatalf("Failed to create port: %v", err) - } + require.NoError(t, err) name := "queryorchestration" pass := "pass" @@ -64,18 +63,12 @@ func CreateDB(t testing.TB, ctx context.Context, cfg *CreateDatabaseConfig) (tes ContainerRequest: req, Started: true, }) - if err != nil { - t.Fatalf("Failed to start container: %v", err) - } + require.NoError(t, err) host, err := container.Host(ctx) - if err != nil { - t.Fatalf("Failed to extract host: %v", err) - } + require.NoError(t, err) mappedPort, err := container.MappedPort(ctx, port) - if err != nil { - t.Fatalf("Failed to extract port: %v", err) - } + require.NoError(t, err) dbcfg := &database.DBConfig{ DBName: name, @@ -101,14 +94,10 @@ func CreateDB(t testing.TB, ctx context.Context, cfg *CreateDatabaseConfig) (tes if cfg.RunMigrations { err := migrations.Run(ctx, cfg.Cfg) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = cfg.Cfg.SetDBPool(ctx) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } if cfg.Network != nil { @@ -119,8 +108,6 @@ func CreateDB(t testing.TB, ctx context.Context, cfg *CreateDatabaseConfig) (tes return container, func() { err := container.Terminate(ctx) - if err != nil { - t.Error(err) - } + require.NoError(t, err) } } diff --git a/internal/test/ecosystem.go b/internal/test/ecosystem.go index 2d86dfc2..b01dfbc8 100644 --- a/internal/test/ecosystem.go +++ b/internal/test/ecosystem.go @@ -7,6 +7,7 @@ import ( "queryorchestration/internal/serviceconfig/database" "testing" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" ) @@ -60,9 +61,7 @@ func CreateRunnersAndServicesNetwork(t testing.TB, ctx context.Context, ncfg *Ec if ncfg.Cfg.GetQueueClient() == nil { err := ncfg.Cfg.SetQueueClient(ctx) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } qs := make(map[string]*Container, len(ncfg.Runners)) @@ -194,9 +193,7 @@ func CreateRunnerNetwork(t testing.TB, ctx context.Context, rcfg *RunnerNetworkC if rcfg.Cfg.GetQueueClient() == nil { err := rcfg.Cfg.SetQueueClient(ctx) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } url := rcfg.QueueURL diff --git a/internal/test/network.go b/internal/test/network.go index 9e9413d0..d74f9d42 100644 --- a/internal/test/network.go +++ b/internal/test/network.go @@ -4,15 +4,14 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/network" ) func CreateNetwork(t testing.TB, ctx context.Context) (*testcontainers.DockerNetwork, func()) { network, err := network.New(ctx, network.WithDriver("bridge")) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return network, func() { testcontainers.CleanupNetwork(t, network) diff --git a/internal/test/objectstore.go b/internal/test/objectstore.go index eecb4a9f..17ab5270 100644 --- a/internal/test/objectstore.go +++ b/internal/test/objectstore.go @@ -7,27 +7,22 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/stretchr/testify/require" ) func CreateBucket(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, name string) { _, err := cfg.GetStoreClient().CreateBucket(ctx, &s3.CreateBucketInput{ Bucket: aws.String(name), }) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = cfg.PingStoreByName(ctx, name) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } func CreateStoreClient(t testing.TB, ctx context.Context, cfg objectstore.ConfigProvider, endpoint string) { cfg.SetS3Endpoint(endpoint) cfg.SetS3UsePathStyle(true) err := cfg.SetStoreClient(ctx) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } diff --git a/internal/test/queue.go b/internal/test/queue.go index a21c7aa3..a6a47288 100644 --- a/internal/test/queue.go +++ b/internal/test/queue.go @@ -11,20 +11,17 @@ import ( "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func CreateQueue(t testing.TB, ctx context.Context, cfg serviceconfig.ConfigProvider, name string) string { queueM, err := cfg.GetQueueClient().CreateQueue(ctx, &sqs.CreateQueueInput{ QueueName: aws.String(name), }) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = cfg.PingQueueByURL(ctx, *queueM.QueueUrl) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return *queueM.QueueUrl } diff --git a/internal/test/service.go b/internal/test/service.go index 4d19034b..d5cb2d76 100644 --- a/internal/test/service.go +++ b/internal/test/service.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/docker/go-connections/nat" + "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" ) @@ -26,9 +27,7 @@ type ServiceConfig struct { func CreateService(t testing.TB, ctx context.Context, config *ServiceConfig) (*Container, func()) { port, err := nat.NewPort("tcp", "8080") - if err != nil { - t.Fatalf("Failed to create port: %v", err) - } + require.NoError(t, err) container, cleanup := createContainer(t, ctx, &containerConfig{ Cfg: config.Cfg, @@ -39,13 +38,9 @@ func CreateService(t testing.TB, ctx context.Context, config *ServiceConfig) (*C }) host, err := container.Host(ctx) - if err != nil { - t.Fatalf("Failed to extract host: %v", err) - } + require.NoError(t, err) mappedPort, err := container.MappedPort(ctx, port) - if err != nil { - t.Fatalf("Failed to extract port: %v", err) - } + require.NoError(t, err) address := fmt.Sprintf("http://%s:%s", host, mappedPort.Port()) diff --git a/scripts/Taskfile.yml b/scripts/Taskfile.yml index 6176d456..fe7cb92a 100644 --- a/scripts/Taskfile.yml +++ b/scripts/Taskfile.yml @@ -1,7 +1,7 @@ --- # https://taskfile.dev -version: '3' +version: "3" vars: CONTEXT: .. @@ -48,6 +48,11 @@ tasks: build:nogen: cmds: - task: docker:build + generate:clean: + deps: + - db:generate:clean + - openapi:generate + - test:mocks:generate generate: deps: - db:generate diff --git a/scripts/database.yml b/scripts/database.yml index 869ab504..708f0a4b 100644 --- a/scripts/database.yml +++ b/scripts/database.yml @@ -1,7 +1,7 @@ --- # https://taskfile.dev -version: '3' +version: "3" vars: MIGRATIONS: "database/migrations" @@ -12,7 +12,7 @@ tasks: - mig cmds: - sqlc generate --file sqlc.yml - regenerate: + generate:clean: cmds: - task compose:clean:generate - task db:generate diff --git a/scripts/tests.yml b/scripts/tests.yml index 6759850e..54b2e38b 100644 --- a/scripts/tests.yml +++ b/scripts/tests.yml @@ -1,7 +1,7 @@ --- # https://taskfile.dev -version: '3' +version: "3" vars: COVERAGE_FILE: "{{.OUT_DIR}}/coverage.out" @@ -48,17 +48,39 @@ tasks: cmds: - grep -v ".gen.go" {{.COVERAGE_FILE}} > {{.FILTER_COVERAGE_FILE}} - go tool cover -func={{.FILTER_COVERAGE_FILE}} > {{.TMP_FILE}} - - cat {{.TMP_FILE}} - | COVERAGE=$(grep total: {{.TMP_FILE}} \ | awk '{print $3}' | sed 's/%//' | bc) - echo "" echo "Coverage Threshold: {{.COVERAGE_THRESHOLD}}%" echo "Total Coverage: $COVERAGE%" + if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then - echo "Total Coverage below Coverage Threshold" + echo "❌ Error: Total Coverage below Coverage Threshold" + FAIL=true + fi + + echo "Function Coverage Threshold: {{.FUNCTION_COVERAGE_THRESHOLD}}%" + FAIL_FUNC=false + grep -v total: {{.TMP_FILE}} | while read -r line; do + FUNC_COV=$(echo "$line" | awk '{print $3}' | sed 's/%//' | bc) + if (( $(echo "$FUNC_COV < \ + {{.FUNCTION_COVERAGE_THRESHOLD}}" | bc -l) )); then + if [ "$FAIL_FUNC" = false ]; then + echo "❌ Error: The following functions have coverage below "\ + "{{.FUNCTION_COVERAGE_THRESHOLD}}%:" + FAIL_FUNC=true + FAIL=true + fi + + echo "$line" + fi + done + + if [ "$FAIL" = true ]; then exit 1 fi + + echo "✅ All coverage checks passed!" silent: true endtoend: cmds: diff --git a/test/process_test.go b/test/process_test.go index b8fc6dcd..4976a1cd 100644 --- a/test/process_test.go +++ b/test/process_test.go @@ -18,6 +18,7 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/oapi-codegen/runtime/types" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type ProcessConfig struct { @@ -43,7 +44,7 @@ func TestProcess(t *testing.T) { defer clean() err := cfg.SetQueueClient(ctx) - assert.NoError(t, err) + require.NoError(t, err) test.CreateStoreClient(t, ctx, cfg, acfg.ExternalEndpoint) dociniturl := test.CreateQueue(t, ctx, cfg, test.DocInitRunner) @@ -71,7 +72,7 @@ func TestProcess(t *testing.T) { }, }, }) - assert.NoError(t, err) + require.NoError(t, err) net, cleanup := test.CreateRunnersAndServicesNetwork(t, ctx, &test.EcosystemNetworkConfig{ Cfg: cfg, @@ -148,7 +149,7 @@ func TestProcess(t *testing.T) { defer cleanup() qService, err := queryservice.NewClientWithResponses(net.Services[test.QueryService].URI) - assert.NoError(t, err) + require.NoError(t, err) clientRes, err := qService.CreateClientWithResponse(ctx, queryservice.ClientCreate{ Name: "example_name", @@ -252,7 +253,7 @@ func WaitForJobStatus(t testing.TB, ctx context.Context, service *queryservice.C for { select { case <-timeout: - t.Fatalf("Timeout waiting for job status to become %s", status) + require.NoError(t, fmt.Errorf("Timeout waiting for job status to become %s", status)) case <-ticker.C: jRes, err := service.GetJobWithResponse(ctx, id) if err != nil {