2025-01-10 19:17:20 +00:00
|
|
|
package controllers_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2025-01-15 19:45:51 +00:00
|
|
|
controllers "queryorchestration/api/queryRunner"
|
2025-01-10 19:17:20 +00:00
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
2025-01-29 11:52:37 +00:00
|
|
|
documenttext "queryorchestration/internal/document/text"
|
2025-01-21 12:28:46 +00:00
|
|
|
"queryorchestration/internal/job/collector"
|
2025-01-23 14:56:20 +00:00
|
|
|
"queryorchestration/internal/query"
|
2025-01-29 11:52:37 +00:00
|
|
|
"queryorchestration/internal/query/result"
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-01-10 19:17:20 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/pashagolub/pgxmock/v3"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestQueryRunner(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)
|
|
|
|
|
|
|
|
|
|
svc := query.New(cfg, &query.Services{
|
|
|
|
|
Result: result.New(cfg),
|
2025-01-29 11:52:37 +00:00
|
|
|
Text: documenttext.New(),
|
2025-01-31 13:43:55 +00:00
|
|
|
Collector: collector.New(cfg, &collector.Services{}),
|
2025-01-21 12:28:46 +00:00
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
runner := controllers.NewQueryRunner(validator.New(), &controllers.Services{
|
2025-01-29 11:52:37 +00:00
|
|
|
Query: svc,
|
2025-01-24 16:12:25 +00:00
|
|
|
})
|
2025-01-10 19:17:20 +00:00
|
|
|
assert.NotNil(t, runner)
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
doc := query.Document{
|
2025-01-10 19:17:20 +00:00
|
|
|
ID: uuid.New(),
|
|
|
|
|
JobID: uuid.New(),
|
|
|
|
|
CleanVersion: 1,
|
|
|
|
|
TextVersion: 1,
|
|
|
|
|
}
|
|
|
|
|
bodyBytes, err := json.Marshal(doc)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
body := string(bodyBytes)
|
|
|
|
|
msg := &types.Message{
|
|
|
|
|
Body: &body,
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
pool.ExpectQuery("name: ListUnsyncedQueriesByDocId :many").WithArgs(database.MustToDBUUID(doc.ID)).
|
2025-01-10 19:17:20 +00:00
|
|
|
WillReturnRows(
|
2025-01-29 11:52:37 +00:00
|
|
|
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}),
|
2025-01-10 19:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
2025-01-20 13:51:22 +00:00
|
|
|
err = runner.Process(ctx, msg)
|
2025-01-10 19:17:20 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
}
|