62886dbba8
Remove Job * removejob * rmjob * sync * cleanup * precommit * startslow * startslow * startslow * openapi * clean * test * scripts * littlecleanercmds * mermaid
76 lines
2.5 KiB
Go
76 lines
2.5 KiB
Go
package querytest_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"queryorchestration/internal/collector"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
cleanversion "queryorchestration/internal/document/clean/version"
|
|
textversion "queryorchestration/internal/document/text/version"
|
|
"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/jackc/pgx/v5/pgtype"
|
|
"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, &collector.Services{
|
|
TextVersion: textversion.New(cfg),
|
|
CleanVersion: cleanversion.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.Document{
|
|
ID: uuid.New(),
|
|
}
|
|
params := &result.Process{
|
|
QueryID: uuid.New(),
|
|
DocumentID: doc.ID,
|
|
QueryVersion: int32(1),
|
|
}
|
|
|
|
reqID := database.MustToDBUUID(uuid.New())
|
|
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion).WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
AddRow(database.MustToDBUUID(params.QueryID), repository.QuerytypeJsonExtractor, int32(1), params.QueryVersion+1, []byte("{\"path\":\"oldkey\"}"), []pgtype.UUID{reqID}),
|
|
)
|
|
strVal := "{\"mykey\":\"example_value\",\"oldkey\":\"old_value\"}"
|
|
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion, database.MustToDBUUID(params.DocumentID)).
|
|
WillReturnRows(
|
|
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
|
AddRow(database.MustToDBUUID(uuid.New()), reqID, repository.QuerytypeContextFull, &strVal),
|
|
)
|
|
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(database.MustToDBUUID(params.QueryID)).WillReturnRows(
|
|
pgxmock.NewRows([]string{"config"}).
|
|
AddRow([]byte("{\"path\":\"oldkey\"}")),
|
|
)
|
|
|
|
result, err := svc.Test(ctx, *params)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "old_value", result)
|
|
}
|