Skip to content

Commit da8cbc1

Browse files
authored
QueueAPI interface defines the minimum interface. (#13)
It is the minimum interface that Worker requires from a queue implementation.
1 parent 710f222 commit da8cbc1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

worker/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (config *Config) populateDefaultValues() {
2626
}
2727
}
2828

29-
func getQueueURL(client sqsiface.SQSAPI, queueName string) (queueURL string) {
29+
func getQueueURL(client QueueAPI, queueName string) (queueURL string) {
3030
params := &sqs.GetQueueUrlInput{
3131
QueueName: aws.String(queueName), // Required
3232
}

worker/worker.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/aws/aws-sdk-go/aws"
1010
"github.com/aws/aws-sdk-go/service/sqs"
11-
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
1211
)
1312

1413
// HandlerFunc is used to define the Handler that is run on for each message
@@ -39,11 +38,18 @@ func NewInvalidEventError(event, msg string) InvalidEventError {
3938
return InvalidEventError{event: event, msg: msg}
4039
}
4140

41+
// QueueAPI interface is the minimum interface required from a queue implementation
42+
type QueueAPI interface {
43+
DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
44+
GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)
45+
ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)
46+
}
47+
4248
// Worker struct
4349
type Worker struct {
4450
Config *Config
4551
Log LoggerIFace
46-
SqsClient sqsiface.SQSAPI
52+
SqsClient QueueAPI
4753
}
4854

4955
// Config struct
@@ -55,7 +61,7 @@ type Config struct {
5561
}
5662

5763
// New sets up a new Worker
58-
func New(client sqsiface.SQSAPI, config *Config) *Worker {
64+
func New(client QueueAPI, config *Config) *Worker {
5965
config.populateDefaultValues()
6066
config.QueueURL = getQueueURL(client, config.QueueName)
6167

worker/worker_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import (
99

1010
"github.com/aws/aws-sdk-go/aws"
1111
"github.com/aws/aws-sdk-go/service/sqs"
12-
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/mock"
1514
)
1615

1716
type mockedSqsClient struct {
1817
Config *aws.Config
1918
Response sqs.ReceiveMessageOutput
20-
sqsiface.SQSAPI
19+
QueueAPI
2120
mock.Mock
2221
}
2322

0 commit comments

Comments
 (0)