Files
query-orchestration/internal/query/list_test.go
T
Michael McGuinness 7ce7c9df4d Merged in feature/ecr (pull request #161)
Feature/ecr

* nosave

* repo

* awscli

* unzip

* ignore

* moreram

* 14k

* ref

* deployment

* 12k

* uselocal

* go

* dockercomd

* reorder

* iamgename

* installs

* tart

* cli

* clideps

* y

* dockerce

* nodock

* multi

* rmecr

* dev
2025-06-03 13:52:10 +00:00

87 lines
2.3 KiB
Go

package query_test
import (
"testing"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/query"
resultprocessor "queryorchestration/internal/query/result/processor"
"queryorchestration/internal/serviceconfig"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)
func TestList(t *testing.T) {
ctx := t.Context()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := query.New(cfg)
config := "{\"path\":\"example_path\"}"
q := &query.Query{
ID: uuid.New(),
Type: resultprocessor.TypeJsonExtractor,
ActiveVersion: int32(1),
LatestVersion: int32(1),
RequiredQueryIDs: &[]uuid.UUID{
uuid.New(),
},
Config: &config,
}
dbReqIDs := *q.RequiredQueryIDs
pool.ExpectQuery("name: ListQueries :many").WithArgs().WillReturnRows(
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
AddRow(q.ID, repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
)
resList, err := svc.List(ctx)
require.NoError(t, err)
assert.EqualExportedValues(t, []*query.Query{q}, resList)
}
func TestListById(t *testing.T) {
ctx := t.Context()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := query.New(cfg)
config := "{\"path\":\"example_path\"}"
q := &query.Query{
ID: uuid.New(),
Type: resultprocessor.TypeJsonExtractor,
ActiveVersion: int32(1),
LatestVersion: int32(1),
RequiredQueryIDs: &[]uuid.UUID{
uuid.New(),
},
Config: &config,
}
dbReqIDs := *q.RequiredQueryIDs
pool.ExpectQuery("name: ListQueriesById :many").WithArgs([]uuid.UUID{q.ID}).WillReturnRows(
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
AddRow(q.ID, repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
)
resList, err := svc.ListById(ctx, []uuid.UUID{q.ID})
require.NoError(t, err)
assert.EqualExportedValues(t, []*query.Query{q}, resList)
}