2025-02-11 15:22:59 +00:00
|
|
|
package querytest_test
|
2025-01-06 14:40:43 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
2025-01-29 11:52:37 +00:00
|
|
|
"queryorchestration/internal/document"
|
2025-02-12 19:00:25 +00:00
|
|
|
cleanversion "queryorchestration/internal/document/clean/version"
|
|
|
|
|
textversion "queryorchestration/internal/document/text/version"
|
2025-01-29 11:52:37 +00:00
|
|
|
"queryorchestration/internal/job/collector"
|
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
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2025-01-29 11:52:37 +00:00
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
2025-01-06 14:40:43 +00:00
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestTest(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
pool, err := pgxmock.NewPool()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to open pgxmock database: %v", err)
|
|
|
|
|
}
|
2025-01-31 13:43:55 +00:00
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
|
|
|
cfg.DBPool = pool
|
|
|
|
|
cfg.DBQueries = repository.New(pool)
|
|
|
|
|
col := collector.New(cfg, &collector.Services{
|
2025-02-12 19:00:25 +00:00
|
|
|
TextVersion: textversion.New(cfg),
|
|
|
|
|
CleanVersion: cleanversion.New(cfg),
|
2025-01-29 11:52:37 +00:00
|
|
|
})
|
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-01-29 11:52:37 +00:00
|
|
|
doc := document.Document{
|
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-01-29 11:52:37 +00:00
|
|
|
reqID := database.MustToDBUUID(uuid.New())
|
2025-02-14 10:56:24 +00:00
|
|
|
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion).WillReturnRows(
|
2025-01-29 11:52:37 +00:00
|
|
|
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}),
|
|
|
|
|
)
|
2025-02-20 19:02:44 +00:00
|
|
|
strVal := "{\"mykey\":\"example_value\",\"oldkey\":\"old_value\"}"
|
|
|
|
|
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion, database.MustToDBUUID(params.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"}).
|
|
|
|
|
AddRow(database.MustToDBUUID(uuid.New()), reqID, repository.QuerytypeContextFull, &strVal),
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
2025-02-20 19:02:44 +00:00
|
|
|
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(database.MustToDBUUID(params.QueryID)).WillReturnRows(
|
|
|
|
|
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-02-03 17:30:50 +00:00
|
|
|
assert.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
|
|
|
}
|