Files
query-orchestration/internal/serviceconfig/queue/config_test.go
T
Michael McGuinness 0815cb35fb Merged in feature/lint (pull request #87)
Basic Lint Checks

* basic
2025-03-05 12:05:46 +00:00

73 lines
1.6 KiB
Go

package queue_test
import (
"context"
"os"
"testing"
"queryorchestration/internal/serviceconfig/queue"
queuemock "queryorchestration/mocks/queue"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestGetQueueClient(t *testing.T) {
c := queue.QueueConfig{}
assert.Nil(t, c.GetQueueClient())
c.QueueClient = &sqs.Client{}
assert.Equal(t, &sqs.Client{}, c.GetQueueClient())
}
func TestSetQueueClient(t *testing.T) {
os.Clearenv()
ctx := context.Background()
c := queue.QueueConfig{}
err := c.SetQueueClient(ctx)
assert.NoError(t, err)
assert.NotNil(t, c.QueueClient)
}
func TestPingQueueByURL(t *testing.T) {
ctx := context.Background()
mockSQS := queuemock.NewMockSQSClient(t)
c := queue.QueueConfig{
QueueClient: mockSQS,
}
url := "i/am/here"
mockSQS.EXPECT().
GetQueueAttributes(
mock.Anything,
mock.MatchedBy(func(in *sqs.GetQueueAttributesInput) bool {
return *in.QueueUrl == url
}),
mock.Anything,
).
Return(&sqs.GetQueueAttributesOutput{}, nil)
err := c.PingQueueByURL(ctx, url)
assert.NoError(t, err)
}
func TestGetSQSEndpoint(t *testing.T) {
cfg := queue.QueueConfig{}
name := cfg.GetSQSEndpoint()
assert.Equal(t, "", name)
cfg.AWSEndpointUrlSQS = "name"
name = cfg.GetSQSEndpoint()
assert.Equal(t, "name", name)
assert.Equal(t, cfg.AWSEndpointUrlSQS, name)
}
func TestSetSQSEndpoint(t *testing.T) {
cfg := queue.QueueConfig{}
assert.Equal(t, "", cfg.AWSEndpointUrlSQS)
url := "/i/am/here"
cfg.SetSQSEndpoint(url)
assert.Equal(t, url, cfg.AWSEndpointUrlSQS)
}