Merged in feature/momocks (pull request #150)
Decrease Mocks * feature/nomocks * nonet * assertsaws * assert
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package docsyncrunner_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,31 +13,30 @@ import (
|
||||
documentsync "queryorchestration/internal/document/sync"
|
||||
"queryorchestration/internal/server/runner"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||
"queryorchestration/internal/test"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type DocSyncConfig struct {
|
||||
runner.BaseConfig[docsyncrunner.Body]
|
||||
documentclean.DocCleanConfig
|
||||
queue.QueueConfig
|
||||
objectstore.ObjectStoreConfig
|
||||
}
|
||||
|
||||
func TestDocSyncRunner(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := &DocSyncConfig{}
|
||||
net := test.GetNetwork(t)
|
||||
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||
ctx := context.Background()
|
||||
test.CreateDB(t, cfg)
|
||||
acfg := test.CreateAWSContainer(t, cfg)
|
||||
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg.QueueClient = mockSQS
|
||||
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
||||
cfg.DocumentCleanURL = test.CreateQueue(t, cfg, test.DocCleanRunnerName)
|
||||
|
||||
runner := docsyncrunner.New(&docsyncrunner.Services{
|
||||
Document: documentsync.New(cfg, &documentsync.Services{
|
||||
@@ -78,19 +77,11 @@ func TestDocSyncRunner(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == cfg.DocumentCleanURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", docId)
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
doc := docsyncrunner.Body{
|
||||
DocumentID: docId,
|
||||
}
|
||||
|
||||
assert.True(t, runner.Process(ctx, doc))
|
||||
assert.True(t, runner.Process(t.Context(), doc))
|
||||
|
||||
test.AssertMessageBody(t, cfg, cfg.GetDocumentCleanURL(), regexp.MustCompile(fmt.Sprintf("{\"id\":\"%s\"}", docId)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user