package queryversionsync import ( "context" "fmt" "testing" "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 := []string{ "hello", "aarete", } pool.ExpectQuery("name: ListQueryClientIDs :many").WithArgs(&queryId). WillReturnRows( pgxmock.NewRows([]string{"clientId"}). AddRow(clientIds[0]). AddRow(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]) }), 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]) }), mock.Anything, ). Return(&sqs.SendMessageOutput{}, nil) assert.Nil(t, svc.Sync(ctx, queryId)) }