-
Notifications
You must be signed in to change notification settings - Fork 4
/
sqs_queue_config_test.go
130 lines (104 loc) · 3.4 KB
/
sqs_queue_config_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package remoteconfig
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
const (
VALID_SQS_QUEUE_REGION AWSRegion = AWS_REGION_US_EAST_1
VALID_SQS_QUEUE_AWS_ACCOUNT_ID string = "345833302425"
VALID_SQS_QUEUE_QUEUE_NAME string = "testQueue"
VALID_SQS_QUEUE_NO_ENDPOINT string = ""
VALID_SQS_QUEUE_ENDPOINT string = "http://localhost:9500"
)
var (
VALID_SQS_QUEUE_URL string = fmt.Sprintf("https://sqs.%s.amazonaws.com/%s/%s", VALID_SQS_QUEUE_REGION, VALID_SQS_QUEUE_AWS_ACCOUNT_ID, VALID_SQS_QUEUE_QUEUE_NAME)
VALID_SQS_QUEUE_URL_ENDPOINT string = fmt.Sprintf("%s/%s/%s", VALID_SQS_QUEUE_ENDPOINT, VALID_SQS_QUEUE_AWS_ACCOUNT_ID, VALID_SQS_QUEUE_QUEUE_NAME)
)
type SQSQueueConfigSuite struct {
suite.Suite
}
func TestSQSQueueConfigSuite(t *testing.T) {
suite.Run(t, new(SQSQueueConfigSuite))
}
func (s *SQSQueueConfigSuite) SetupSuite() {
}
func (s *SQSQueueConfigSuite) SetupTest() {
}
func (s *SQSQueueConfigSuite) TestValidate() {
region := VALID_SQS_QUEUE_REGION
awsAccountID := VALID_SQS_QUEUE_AWS_ACCOUNT_ID
queueName := VALID_SQS_QUEUE_QUEUE_NAME
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
err := validateConfigWithReflection(c)
assert.Nil(s.T(), err)
}
func (s *SQSQueueConfigSuite) TestValidateErrorRegion() {
region := AWSRegion("invalidregion")
awsAccountID := VALID_SQS_QUEUE_AWS_ACCOUNT_ID
queueName := VALID_SQS_QUEUE_QUEUE_NAME
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
err := validateConfigWithReflection(c)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), errors.New("Validater Field: Region, failed to validate with error, Region is invalid"), err)
}
func (s *SQSQueueConfigSuite) TestValidateErrorAWSAccountID() {
region := VALID_SQS_QUEUE_REGION
awsAccountID := ""
queueName := VALID_SQS_QUEUE_QUEUE_NAME
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
err := validateConfigWithReflection(c)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), errors.New("String Field: AWSAccountID, contains an empty string"), err)
}
func (s *SQSQueueConfigSuite) TestValidateErrorQueueName() {
region := VALID_SQS_QUEUE_REGION
awsAccountID := VALID_SQS_QUEUE_AWS_ACCOUNT_ID
queueName := ""
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
err := validateConfigWithReflection(c)
assert.NotNil(s.T(), err)
assert.Equal(s.T(), errors.New("String Field: QueueName, contains an empty string"), err)
}
func (s *SQSQueueConfigSuite) TestGetURLNoEndpoint() {
region := VALID_SQS_QUEUE_REGION
awsAccountID := VALID_SQS_QUEUE_AWS_ACCOUNT_ID
queueName := VALID_SQS_QUEUE_QUEUE_NAME
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
url := c.GetURL(VALID_SQS_QUEUE_NO_ENDPOINT)
assert.Equal(s.T(), VALID_SQS_QUEUE_URL, url)
}
func (s *SQSQueueConfigSuite) TestGetURLWithEndpoint() {
region := VALID_SQS_QUEUE_REGION
awsAccountID := VALID_SQS_QUEUE_AWS_ACCOUNT_ID
queueName := VALID_SQS_QUEUE_QUEUE_NAME
c := &SQSQueueConfig{
Region: ®ion,
AWSAccountID: &awsAccountID,
QueueName: &queueName,
}
url := c.GetURL(VALID_SQS_QUEUE_ENDPOINT)
assert.Equal(s.T(), VALID_SQS_QUEUE_URL_ENDPOINT, url)
}