Merged in feature/functestcov (pull request #84)

Function Test Coverage

* test

* scripts
This commit is contained in:
Michael McGuinness
2025-03-04 15:51:03 +00:00
parent 4b8c930ff1
commit d91ef1832b
85 changed files with 446 additions and 489 deletions
+2 -1
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+4 -9
View File
@@ -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
+2 -3
View File
@@ -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
+4 -9
View File
@@ -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)
+3 -6
View File
@@ -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)
+7 -15
View File
@@ -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)
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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)
+2 -3
View File
@@ -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)
+2 -3
View File
@@ -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)
+3 -6
View File
@@ -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)
+3 -6
View File
@@ -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)
@@ -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())
}
@@ -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())
}
+4 -6
View File
@@ -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
+2 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
+8 -18
View File
@@ -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)
+2 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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
+3 -3
View File
@@ -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)
+4 -9
View File
@@ -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)
+35 -6
View File
@@ -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)
}
+2 -3
View File
@@ -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)
@@ -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)
+2 -3
View File
@@ -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)
@@ -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)
+2 -3
View File
@@ -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)
+4 -6
View File
@@ -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)
+2 -3
View File
@@ -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)
+4 -9
View File
@@ -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)
+3 -6
View File
@@ -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
+2 -3
View File
@@ -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)
+4 -9
View File
@@ -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)
+5 -9
View File
@@ -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)
+5 -12
View File
@@ -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)
+3 -6
View File
@@ -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)
+4 -6
View File
@@ -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)
+2 -3
View File
@@ -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)
+2 -3
View File
@@ -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)
+3 -6
View File
@@ -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)
+2 -3
View File
@@ -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)
+4 -6
View File
@@ -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)
+4 -6
View File
@@ -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)
+2 -3
View File
@@ -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)
+2 -3
View File
@@ -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)
+2 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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)
+16 -42
View File
@@ -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)
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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
@@ -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)
+2 -2
View File
@@ -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
@@ -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"))
}
@@ -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)
}
}
@@ -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)
+5 -12
View File
@@ -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)
+2 -1
View File
@@ -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() {
+8 -21
View File
@@ -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)
}
}
+3 -6
View File
@@ -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
+2 -3
View File
@@ -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)
+4 -9
View File
@@ -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)
}
+3 -6
View File
@@ -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
}
+4 -9
View File
@@ -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())
+6 -1
View File
@@ -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
+2 -2
View File
@@ -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
+26 -4
View File
@@ -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:
+5 -4
View File
@@ -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 {