Merged in feature/testwithlogs (pull request #65)
Query Version Sync Runner * testing * queryversiosyncworking * update * tests * fixtests
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
collectorupdate "queryorchestration/internal/job/collector/update"
|
||||
"queryorchestration/internal/query"
|
||||
querytest "queryorchestration/internal/query/test"
|
||||
queryupdate "queryorchestration/internal/query/update"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
@@ -19,9 +20,10 @@ type Services struct {
|
||||
Collector *collector.Service
|
||||
CollectorUpdate *collectorupdate.Service
|
||||
Query *query.Service
|
||||
QueryUpdate *queryupdate.Service
|
||||
QueryTest *querytest.Service
|
||||
Client *client.Service
|
||||
Job *job.Service
|
||||
QueryTest *querytest.Service
|
||||
}
|
||||
|
||||
type Controllers struct {
|
||||
|
||||
@@ -71,7 +71,7 @@ func (s *Controllers) UpdateQuery(ctx echo.Context, id types.UUID) error {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
err := s.svc.Query.Update(ctx.Request().Context(), &resultprocessor.Update{
|
||||
err := s.svc.QueryUpdate.Update(ctx.Request().Context(), &resultprocessor.Update{
|
||||
ActiveVersion: req.ActiveVersion,
|
||||
Config: req.Config,
|
||||
RequiredQueryIDs: req.RequiredQueries,
|
||||
|
||||
@@ -16,10 +16,14 @@ import (
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
querytest "queryorchestration/internal/query/test"
|
||||
queryupdate "queryorchestration/internal/query/update"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/queryversionsync"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -27,6 +31,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestCreateQuery(t *testing.T) {
|
||||
@@ -159,12 +164,20 @@ func TestUpdateQuery(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg := &struct {
|
||||
serviceconfig.BaseConfig
|
||||
queryversionsync.QueryVersionSyncConfig
|
||||
}{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg.QueueClient = mockSQS
|
||||
cfg.QueryVersionSyncURL = "here"
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Query: query.New(cfg),
|
||||
QueryUpdate: queryupdate.New(cfg, &queryupdate.Services{
|
||||
Query: query.New(cfg),
|
||||
}),
|
||||
})
|
||||
|
||||
av := int32(2)
|
||||
@@ -190,9 +203,18 @@ func TestUpdateQuery(t *testing.T) {
|
||||
)
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectExec("name: UpdateQuery :exec").WithArgs(av, int32(3), database.MustToDBUUID(id)).
|
||||
pool.ExpectExec("name: UpdateQuery :exec").WithArgs(av, int32(2), database.MustToDBUUID(id)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == cfg.QueryVersionSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", id.String())
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
err = cons.UpdateQuery(ctx, id)
|
||||
assert.NoError(t, err)
|
||||
@@ -268,7 +290,7 @@ func TestTestQuery(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(coll.ID), database.MustToDBUUID(doc.JobID), coll.MinCleanVersion, coll.MinTextVersion, int32(1), int32(2), []byte("")),
|
||||
)
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), params.QueryVersion).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion).WillReturnRows(
|
||||
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}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user