-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqs_service_test.go
63 lines (43 loc) · 1.54 KB
/
sqs_service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sqsconsumer
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/tprovoost/sqsconsumer/mock"
)
func TestSetupQueueExists(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
name := "fake_queue_name"
svc := mock.NewMockSQSAPI(ctl)
svc.EXPECT().GetQueueUrl(&sqs.GetQueueUrlInput{QueueName: aws.String(name)}).Return(&sqs.GetQueueUrlOutput{QueueUrl: aws.String("http://example.com/queue/" + name)}, nil)
url, err := SetupQueue(svc, name)
assert.Regexp(t, "/fake_queue_name$", *url)
assert.Nil(t, err)
}
func TestSetupQueue(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
name := "fake_queue_name"
svc := mock.NewMockSQSAPI(ctl)
// Given SQS creates the new queue successfully
svc.EXPECT().GetQueueUrl(gomock.Any()).Return(nil, assert.AnError)
svc.EXPECT().CreateQueue(gomock.Any()).Return(&sqs.CreateQueueOutput{QueueUrl: aws.String("http://example.com/queue/" + name)}, nil)
url, err := SetupQueue(svc, name)
assert.Regexp(t, "/fake_queue_name$", *url)
assert.Nil(t, err)
}
func TestSetupQueueFails(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
name := "fake_queue_name"
svc := mock.NewMockSQSAPI(ctl)
// Given SQS returns an error
svc.EXPECT().GetQueueUrl(gomock.Any()).Return(nil, assert.AnError)
svc.EXPECT().CreateQueue(gomock.Any()).Return(nil, assert.AnError)
url, err := SetupQueue(svc, name)
assert.Nil(t, url)
assert.NotNil(t, err)
}