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(¶ms.QueryID, ¶ms.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(¶ms.QueryID, ¶ms.QueryVersion, ¶ms.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) }