Files
query-orchestration/internal/query/test/test_test.go
T
Michael McGuinness 53ea7d34e6 Merged in feature/textextract (pull request #108)
Start adding Textract + UUID changes

* base

* startclient

* ts

* short

* tests
2025-03-20 11:06:41 +00:00

69 lines
2.1 KiB
Go

package querytest_test
import (
"context"
"testing"
"queryorchestration/internal/collector"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/query"
"queryorchestration/internal/query/result"
querytest "queryorchestration/internal/query/test"
"queryorchestration/internal/serviceconfig"
"github.com/stretchr/testify/require"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestTest(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)
col := collector.New(cfg)
docsvc := document.New(cfg)
svc := querytest.New(cfg, &querytest.Services{
Document: docsvc,
Collector: col,
Result: result.New(cfg, &result.Services{
Query: query.New(cfg),
}),
})
doc := document.DocumentSummary{
ID: uuid.New(),
}
params := &result.Process{
QueryID: uuid.New(),
DocumentID: doc.ID,
QueryVersion: int32(1),
}
reqID := uuid.New()
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(&params.QueryID, &params.QueryVersion).WillReturnRows(
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
AddRow(params.QueryID, repository.QuerytypeJsonExtractor, int32(1), params.QueryVersion+1, []byte("{\"path\":\"oldkey\"}"), []uuid.UUID{reqID}),
)
strVal := "{\"mykey\":\"example_value\",\"oldkey\":\"old_value\"}"
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(&params.QueryID, &params.QueryVersion, &params.DocumentID).
WillReturnRows(
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
AddRow(&uuid.UUID{}, reqID, repository.QuerytypeContextFull, &strVal),
)
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(params.QueryID).WillReturnRows(
pgxmock.NewRows([]string{"config"}).
AddRow([]byte("{\"path\":\"oldkey\"}")),
)
result, err := svc.Test(ctx, *params)
require.NoError(t, err)
assert.Equal(t, "old_value", result)
}