@@ -6,11 +6,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -31,24 +30,13 @@ func TestSetQueueClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPingQueueByURL(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
c := queue.QueueConfig{
|
||||
QueueClient: mockSQS,
|
||||
}
|
||||
url := "i/am/here"
|
||||
cfg := &AWSConfig{}
|
||||
acfg := test.CreateAWSContainer(t, cfg)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
GetQueueAttributes(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.GetQueueAttributesInput) bool {
|
||||
return *in.QueueUrl == url
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.GetQueueAttributesOutput{}, nil)
|
||||
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
||||
cfg.QueryURL = test.CreateQueue(t, cfg, test.QueryRunnerName)
|
||||
|
||||
err := c.PingQueueByURL(ctx, url)
|
||||
err := cfg.PingQueueByURL(t.Context(), cfg.QueryURL)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
func TestGetSQSEndpoint(t *testing.T) {
|
||||
|
||||
@@ -1,39 +1,43 @@
|
||||
package queue_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg := queue.QueueConfig{}
|
||||
cfg.QueueClient = mockSQS
|
||||
handle := "iamahandler"
|
||||
cfg := &AWSConfig{}
|
||||
acfg := test.CreateAWSContainer(t, cfg)
|
||||
|
||||
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
||||
cfg.QueryURL = test.CreateQueue(t, cfg, test.QueryRunnerName)
|
||||
|
||||
err := cfg.SendToQueue(t.Context(), &queue.SendParams{
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
Body: struct {
|
||||
}{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
msg := test.AssertMessage(t, cfg, &queue.ReceiveParams{
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
})
|
||||
|
||||
params := &queue.DeleteParams{
|
||||
ReceiptHandle: &handle,
|
||||
QueueURL: "/i/am/here",
|
||||
ReceiptHandle: msg.ReceiptHandle,
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
}
|
||||
|
||||
mockSQS.EXPECT().
|
||||
DeleteMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.DeleteMessageInput) bool {
|
||||
return *in.QueueUrl == params.QueueURL && *in.ReceiptHandle == handle
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.DeleteMessageOutput{}, nil)
|
||||
|
||||
err := cfg.DeleteFromQueue(ctx, params)
|
||||
err = cfg.DeleteFromQueue(t.Context(), params)
|
||||
require.NoError(t, err)
|
||||
|
||||
ares, err := cfg.ReceiveFromQueue(t.Context(), &queue.ReceiveParams{
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, ares.Messages, 0)
|
||||
}
|
||||
|
||||
@@ -1,41 +1,38 @@
|
||||
package queue_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestReceive(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg := queue.QueueConfig{}
|
||||
cfg.QueueClient = mockSQS
|
||||
cfg := &AWSConfig{}
|
||||
acfg := test.CreateAWSContainer(t, cfg)
|
||||
|
||||
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
||||
cfg.QueryURL = test.CreateQueue(t, cfg, test.QueryRunnerName)
|
||||
|
||||
err := cfg.SendToQueue(t.Context(), &queue.SendParams{
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
Body: struct {
|
||||
Field string
|
||||
}{
|
||||
Field: "value",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &queue.ReceiveParams{
|
||||
QueueURL: "/i/am/here",
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
}
|
||||
|
||||
res := sqs.ReceiveMessageOutput{Messages: []types.Message{}}
|
||||
|
||||
mockSQS.EXPECT().
|
||||
ReceiveMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.ReceiveMessageInput) bool {
|
||||
return *in.QueueUrl == params.QueueURL
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&res, nil)
|
||||
|
||||
ares, err := cfg.ReceiveFromQueue(ctx, params)
|
||||
ares, err := cfg.ReceiveFromQueue(t.Context(), params)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, res, *ares)
|
||||
require.Len(t, ares.Messages, 1)
|
||||
assert.Equal(t, *ares.Messages[0].Body, `{"Field":"value"}`)
|
||||
}
|
||||
|
||||
@@ -1,37 +1,39 @@
|
||||
package queue_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"queryorchestration/internal/serviceconfig/queue/query"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type AWSConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
queue.QueueConfig
|
||||
objectstore.ObjectStoreConfig
|
||||
query.QueryConfig
|
||||
}
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockSQS := queuemock.NewMockSQSClient(t)
|
||||
cfg := queue.QueueConfig{}
|
||||
cfg.QueueClient = mockSQS
|
||||
cfg := &AWSConfig{}
|
||||
acfg := test.CreateAWSContainer(t, cfg)
|
||||
|
||||
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
||||
cfg.QueryURL = test.CreateQueue(t, cfg, test.QueryRunnerName)
|
||||
|
||||
params := &queue.SendParams{
|
||||
QueueURL: "/i/am/here",
|
||||
QueueURL: cfg.GetQueryURL(),
|
||||
Body: struct{}{},
|
||||
}
|
||||
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == params.QueueURL && *in.MessageBody == "{}"
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
err := cfg.SendToQueue(ctx, params)
|
||||
err := cfg.SendToQueue(t.Context(), params)
|
||||
require.NoError(t, err)
|
||||
|
||||
test.AssertMessageBody(t, cfg, cfg.GetQueryURL(), regexp.MustCompile("{}"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user