Skip to content

Commit

Permalink
QueueAPI interface defines the minimum interface. (#13)
Browse files Browse the repository at this point in the history
It is the minimum interface that Worker requires from a
queue implementation.
  • Loading branch information
bernata authored Nov 10, 2020
1 parent 710f222 commit da8cbc1
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion worker/util.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ func (config *Config) populateDefaultValues() {
}
}

func getQueueURL(client sqsiface.SQSAPI, queueName string) (queueURL string) {
func getQueueURL(client QueueAPI, queueName string) (queueURL string) {
params := &sqs.GetQueueUrlInput{
QueueName: aws.String(queueName), // Required
}
12 changes: 9 additions & 3 deletions worker/worker.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
)

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

// QueueAPI interface is the minimum interface required from a queue implementation
type QueueAPI interface {
DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)
ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)
}

// Worker struct
type Worker struct {
Config *Config
Log LoggerIFace
SqsClient sqsiface.SQSAPI
SqsClient QueueAPI
}

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

// New sets up a new Worker
func New(client sqsiface.SQSAPI, config *Config) *Worker {
func New(client QueueAPI, config *Config) *Worker {
config.populateDefaultValues()
config.QueueURL = getQueueURL(client, config.QueueName)

3 changes: 1 addition & 2 deletions worker/worker_test.go
Original file line number Diff line number Diff line change
@@ -9,15 +9,14 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

type mockedSqsClient struct {
Config *aws.Config
Response sqs.ReceiveMessageOutput
sqsiface.SQSAPI
QueueAPI
mock.Mock
}

0 comments on commit da8cbc1

Please sign in to comment.