Files
query-orchestration/api/queryRunner/runner_test.go
T
Michael McGuinness 7001ca854c Merged in feature/docinitialisation (pull request #41)
Queuing Changes and Cfg Testing

* staarting

* staarting

* startedpush

* note

* save

* mocking

* removederrs

* fixtests

* cleanuperrs

* newenvsetup

* preppingtests

* queue

* mmovetocfgpassunittests

* sortoutconfig

* passinginteg

* deps

* fixtests
2025-02-03 17:30:50 +00:00

67 lines
1.7 KiB
Go

package queryrunner_test
import (
"context"
"encoding/json"
controllers "queryorchestration/api/queryRunner"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
documenttext "queryorchestration/internal/document/text"
"queryorchestration/internal/job/collector"
"queryorchestration/internal/query"
"queryorchestration/internal/query/result"
"queryorchestration/internal/serviceconfig"
"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)
}
cfg := &serviceconfig.BaseConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := query.New(cfg, &query.Services{
Result: result.New(cfg),
Text: documenttext.New(),
Collector: collector.New(cfg, &collector.Services{}),
})
runner := controllers.New(validator.New(), &controllers.Services{
Query: svc,
})
assert.NotNil(t, runner)
doc := query.Document{
ID: uuid.New(),
JobID: uuid.New(),
CleanVersion: 1,
TextVersion: 1,
}
bodyBytes, err := json.Marshal(doc)
assert.NoError(t, err)
body := string(bodyBytes)
msg := &types.Message{
Body: &body,
}
pool.ExpectQuery("name: ListUnsyncedQueriesByDocId :many").WithArgs(database.MustToDBUUID(doc.ID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}),
)
err = runner.Process(ctx, msg)
assert.NoError(t, err)
}