15adaebfcd
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
91 lines
2.6 KiB
Go
91 lines
2.6 KiB
Go
package query_test
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestList(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
if err != nil {
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
}
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
svc := query.New(cfg, &query.Services{})
|
|
|
|
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 := database.MustToDBUUIDArray(*q.RequiredQueryIDs)
|
|
|
|
pool.ExpectQuery("name: ListQueries :many").WithArgs().WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(q.ID), repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
resList, err := svc.List(ctx)
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualExportedValues(t, []*query.Query{q}, resList)
|
|
}
|
|
|
|
func TestListById(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
if err != nil {
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
}
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
cfg.DBPool = pool
|
|
cfg.DBQueries = repository.New(pool)
|
|
svc := query.New(cfg, &query.Services{})
|
|
|
|
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 := database.MustToDBUUIDArray(*q.RequiredQueryIDs)
|
|
|
|
pool.ExpectQuery("name: ListQueriesById :many").WithArgs([]pgtype.UUID{database.MustToDBUUID(q.ID)}).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(q.ID), repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
|
)
|
|
|
|
resList, err := svc.ListById(ctx, []uuid.UUID{q.ID})
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualExportedValues(t, []*query.Query{q}, resList)
|
|
}
|