2025-02-11 15:22:59 +00:00
|
|
|
package querytest_test
|
2025-01-06 14:40:43 +00:00
|
|
|
|
|
|
|
|
import (
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-03-10 11:03:00 +00:00
|
|
|
"queryorchestration/internal/collector"
|
2025-01-06 14:40:43 +00:00
|
|
|
"queryorchestration/internal/database/repository"
|
2025-01-29 11:52:37 +00:00
|
|
|
"queryorchestration/internal/document"
|
2025-01-06 14:40:43 +00:00
|
|
|
"queryorchestration/internal/query"
|
2025-01-29 11:52:37 +00:00
|
|
|
"queryorchestration/internal/query/result"
|
2025-02-11 15:22:59 +00:00
|
|
|
querytest "queryorchestration/internal/query/test"
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-01-06 14:40:43 +00:00
|
|
|
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2025-01-06 14:40:43 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestTest(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()
|
2025-03-04 15:51:03 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-31 13:43:55 +00:00
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
|
|
|
cfg.DBPool = pool
|
|
|
|
|
cfg.DBQueries = repository.New(pool)
|
2025-03-10 13:00:57 +00:00
|
|
|
col := collector.New(cfg)
|
2025-02-12 19:00:25 +00:00
|
|
|
docsvc := document.New(cfg)
|
2025-02-11 15:22:59 +00:00
|
|
|
svc := querytest.New(cfg, &querytest.Services{
|
2025-01-29 11:52:37 +00:00
|
|
|
Document: docsvc,
|
|
|
|
|
Collector: col,
|
2025-02-11 15:22:59 +00:00
|
|
|
Result: result.New(cfg, &result.Services{
|
|
|
|
|
Query: query.New(cfg),
|
|
|
|
|
}),
|
2025-01-29 11:52:37 +00:00
|
|
|
})
|
2025-01-06 14:40:43 +00:00
|
|
|
|
2025-03-17 18:14:15 +00:00
|
|
|
doc := document.DocumentSummary{
|
2025-02-20 19:02:44 +00:00
|
|
|
ID: uuid.New(),
|
2025-01-29 11:52:37 +00:00
|
|
|
}
|
2025-02-11 15:22:59 +00:00
|
|
|
params := &result.Process{
|
2025-01-06 14:40:43 +00:00
|
|
|
QueryID: uuid.New(),
|
2025-01-29 11:52:37 +00:00
|
|
|
DocumentID: doc.ID,
|
2025-01-06 14:40:43 +00:00
|
|
|
QueryVersion: int32(1),
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
reqID := uuid.New()
|
|
|
|
|
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(¶ms.QueryID, ¶ms.QueryVersion).WillReturnRows(
|
2025-01-29 11:52:37 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
2025-03-20 11:06:41 +00:00
|
|
|
AddRow(params.QueryID, repository.QuerytypeJsonExtractor, int32(1), params.QueryVersion+1, []byte("{\"path\":\"oldkey\"}"), []uuid.UUID{reqID}),
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
2025-02-20 19:02:44 +00:00
|
|
|
strVal := "{\"mykey\":\"example_value\",\"oldkey\":\"old_value\"}"
|
2025-03-20 11:06:41 +00:00
|
|
|
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(¶ms.QueryID, ¶ms.QueryVersion, ¶ms.DocumentID).
|
2025-01-29 11:52:37 +00:00
|
|
|
WillReturnRows(
|
2025-02-20 19:02:44 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
2025-03-20 11:06:41 +00:00
|
|
|
AddRow(&uuid.UUID{}, reqID, repository.QuerytypeContextFull, &strVal),
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(params.QueryID).WillReturnRows(
|
2025-02-20 19:02:44 +00:00
|
|
|
pgxmock.NewRows([]string{"config"}).
|
|
|
|
|
AddRow([]byte("{\"path\":\"oldkey\"}")),
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
|
|
|
|
|
2025-01-06 14:40:43 +00:00
|
|
|
result, err := svc.Test(ctx, *params)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-29 11:52:37 +00:00
|
|
|
assert.Equal(t, "old_value", result)
|
2025-01-06 14:40:43 +00:00
|
|
|
}
|