Files
query-orchestration/internal/query/versionsync/sync_test.go
T
Michael McGuinness 62886dbba8 Merged in feature/removejob (pull request #95)
Remove Job

* removejob

* rmjob

* sync

* cleanup

* precommit

* startslow

* startslow

* startslow

* openapi

* clean

* test

* scripts

* littlecleanercmds

* mermaid
2025-03-10 11:03:00 +00:00

75 lines
1.9 KiB
Go

package queryversionsync
import (
"context"
"fmt"
"testing"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue/clientsync"
queuemock "queryorchestration/mocks/queue"
"github.com/stretchr/testify/require"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type QueryVersionSyncConfig struct {
serviceconfig.BaseConfig
clientsync.ClientSyncConfig
}
func TestSync(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &QueryVersionSyncConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
mockSQS := queuemock.NewMockSQSClient(t)
cfg.QueueClient = mockSQS
cfg.ClientSyncURL = "/i/am/here"
svc := Service{cfg}
queryId := uuid.New()
clientIds := []uuid.UUID{
uuid.New(),
uuid.New(),
}
pool.ExpectQuery("name: ListQueryClientIDs :many").WithArgs(database.MustToDBUUID(queryId)).
WillReturnRows(
pgxmock.NewRows([]string{"clientId"}).
AddRow(database.MustToDBUUID(clientIds[0])).
AddRow(database.MustToDBUUID(clientIds[1])),
)
mockSQS.EXPECT().
SendMessage(
mock.Anything,
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
return *in.QueueUrl == cfg.ClientSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", clientIds[0].String())
}),
mock.Anything,
).
Return(&sqs.SendMessageOutput{}, nil)
mockSQS.EXPECT().
SendMessage(
mock.Anything,
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
return *in.QueueUrl == cfg.ClientSyncURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", clientIds[1].String())
}),
mock.Anything,
).
Return(&sqs.SendMessageOutput{}, nil)
assert.Nil(t, svc.Sync(ctx, queryId))
}