Files
query-orchestration/internal/query/list_test.go
T

87 lines
2.3 KiB
Go
Raw Normal View History

2025-01-07 16:30:45 +00:00
package query_test
2025-01-06 14:40:43 +00:00
import (
2025-03-05 12:05:46 +00:00
"testing"
2025-01-06 14:40:43 +00:00
"queryorchestration/internal/database/repository"
"queryorchestration/internal/query"
resultprocessor "queryorchestration/internal/query/result/processor"
"queryorchestration/internal/serviceconfig"
2025-01-06 14:40:43 +00:00
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/require"
2025-01-06 14:40:43 +00:00
"github.com/stretchr/testify/assert"
)
func TestList(t *testing.T) {
2025-06-03 13:52:10 +00:00
ctx := t.Context()
2025-01-06 14:40:43 +00:00
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),
2025-01-20 13:31:48 +00:00
RequiredQueryIDs: &[]uuid.UUID{
uuid.New(),
},
2025-01-20 13:31:48 +00:00
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)
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
assert.EqualExportedValues(t, []*query.Query{q}, resList)
}
func TestListById(t *testing.T) {
2025-06-03 13:52:10 +00:00
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)
2025-01-06 14:40:43 +00:00
config := "{\"path\":\"example_path\"}"
2025-01-06 15:31:39 +00:00
q := &query.Query{
2025-01-06 14:40:43 +00:00
ID: uuid.New(),
Type: resultprocessor.TypeJsonExtractor,
2025-01-06 14:40:43 +00:00
ActiveVersion: int32(1),
LatestVersion: int32(1),
2025-01-20 13:31:48 +00:00
RequiredQueryIDs: &[]uuid.UUID{
2025-01-06 14:40:43 +00:00
uuid.New(),
},
2025-01-20 13:31:48 +00:00
Config: &config,
2025-01-06 14:40:43 +00:00
}
dbReqIDs := *q.RequiredQueryIDs
2025-01-06 14:40:43 +00:00
pool.ExpectQuery("name: ListQueriesById :many").WithArgs([]uuid.UUID{q.ID}).WillReturnRows(
2025-01-06 14:40:43 +00:00
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
AddRow(q.ID, repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
2025-01-06 14:40:43 +00:00
)
resList, err := svc.ListById(ctx, []uuid.UUID{q.ID})
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
2025-01-06 14:40:43 +00:00
2025-01-06 15:31:39 +00:00
assert.EqualExportedValues(t, []*query.Query{q}, resList)
2025-01-06 14:40:43 +00:00
}