Files
query-orchestration/internal/server/runner/poll_test.go
T

78 lines
1.6 KiB
Go
Raw Normal View History

package runner
2025-01-10 11:12:03 +00:00
import (
"context"
queuemock "queryorchestration/mocks/queue"
runnermock "queryorchestration/mocks/runner"
2025-01-10 11:12:03 +00:00
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/service/sqs"
2025-01-10 11:12:03 +00:00
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
2025-01-10 11:12:03 +00:00
)
func TestPollMessages(t *testing.T) {
ctx := context.Background()
mockSQS := queuemock.NewMockSQSClient(t)
cfg := &BaseConfig{}
cfg.QueueClient = mockSQS
cfg.ControllerFunc = func() Controller {
return runnermock.NewMockController(t)
}
cfg.QueueURL = "/i/am/here"
res := sqs.ReceiveMessageOutput{Messages: []types.Message{}}
mockSQS.EXPECT().
ReceiveMessage(
mock.Anything,
mock.MatchedBy(func(in *sqs.ReceiveMessageInput) bool {
return *in.QueueUrl == cfg.QueueURL
}),
mock.Anything,
).
Return(&res, nil)
2025-01-10 11:12:03 +00:00
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
scfg := &Server{
cfg: cfg,
cleanup: func() error { return nil },
}
scfg.Listen(ctx)
2025-01-10 11:12:03 +00:00
}
func TestPollMessage(t *testing.T) {
ctx := context.Background()
mockSQS := queuemock.NewMockSQSClient(t)
cfg := &BaseConfig{}
cfg.QueueClient = mockSQS
cfg.ControllerFunc = func() Controller {
return runnermock.NewMockController(t)
}
cfg.QueueURL = "/i/am/here"
2025-01-10 11:12:03 +00:00
ser := &Server{
cfg: cfg,
cleanup: func() error { return nil },
}
mockSQS.EXPECT().
ReceiveMessage(
mock.Anything,
mock.MatchedBy(func(in *sqs.ReceiveMessageInput) bool {
return *in.QueueUrl == cfg.QueueURL
}),
mock.Anything,
).
Return(&sqs.ReceiveMessageOutput{}, nil)
err := ser.pollMessage(ctx)
assert.NoError(t, err)
2025-01-10 11:12:03 +00:00
}