-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4]: bug(attributes): case sensitive sqs attributes
- Loading branch information
Showing
11 changed files
with
381 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Linux | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags-ignore: | ||
- "**" | ||
paths-ignore: | ||
- "**.md" | ||
- "**.yaml" | ||
- "**.yml" | ||
pull_request: | ||
paths-ignore: | ||
- "**.md" | ||
- "**.yaml" | ||
- "**.yml" | ||
|
||
jobs: | ||
golang: | ||
name: Build (Go ${{ matrix.go }}, OS ${{matrix.os}}) | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
go: [ "1.17.6" ] | ||
os: [ "ubuntu-latest" ] | ||
steps: | ||
- name: Set up Go ${{ matrix.go }} | ||
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go> | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules> | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ runner.os }}-go- | ||
|
||
- name: Install Go dependencies | ||
run: go mod download | ||
|
||
- name: Run golang tests with coverage | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test: | ||
go test -v -race -cover -tags=debug ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package sqsjobs | ||
|
||
const ( | ||
Policy string = "policy" | ||
PolicyAWS string = "Policy" | ||
VisibilityTimeout string = "visibilitytimeout" | ||
VisibilityTimeoutAWS string = "VisibilityTimeout" | ||
MaximumMessageSize string = "maximummessagesize" | ||
MaximumMessageSizeAWS string = "MaximumMessageSize" | ||
MessageRetentionPeriod string = "messageretentionperiod" | ||
MessageRetentionPeriodAWS string = "MessageRetentionPeriod" | ||
ApproximateNumberOfMessages string = "approximatenumberofmessages" | ||
ApproximateNumberOfMessagesAWS string = "ApproximateNumberOfMessages" | ||
ApproximateNumberOfMessagesNotVisible string = "approximatenumberofmessagesnotvisible" | ||
ApproximateNumberOfMessagesNotVisibleAWS string = "ApproximateNumberOfMessagesNotVisible" | ||
CreatedTimestamp string = "createdtimestamp" | ||
CreatedTimestampAWS string = "CreatedTimestamp" | ||
LastModifiedTimestamp string = "lastmodifiedtimestamp" | ||
LastModifiedTimestampAWS string = "LastModifiedTimestamp" | ||
QueueArn string = "queuearn" | ||
QueueArnAWS string = "QueueArn" | ||
ApproximateNumberOfMessagesDelayed string = "approximatenumberofmessagesdelayed" | ||
ApproximateNumberOfMessagesDelayedAWS string = "ApproximateNumberOfMessagesDelayed" | ||
DelaySeconds string = "delayseconds" | ||
DelaySecondsAWS string = "DelaySeconds" | ||
RedrivePolicy string = "redrivepolicy" | ||
RedrivePolicyAWS string = "RedrivePolicy" | ||
FifoQueue string = "fifoqueue" | ||
FifoQueueAWS string = "FifoQueue" | ||
ContentBasedDeduplication string = "contentbaseddeduplication" | ||
ContentBasedDeduplicationAWS string = "ContentBasedDeduplication" | ||
KmsMasterKeyID string = "kmsmasterkeyid" | ||
KmsMasterKeyIDAWS string = "KmsMasterKeyId" | ||
KmsDataKeyReusePeriodSeconds string = "kmsdatakeyreuseperiodseconds" | ||
KmsDataKeyReusePeriodSecondsAWS string = "KmsDataKeyReusePeriodSeconds" | ||
DeduplicationScope string = "deduplicationscope" | ||
DeduplicationScopeAWS string = "DeduplicationScope" | ||
FifoThroughputLimit string = "fifothroughputlimit" | ||
FifoThroughputLimitAWS string = "FifoThroughputLimit" | ||
RedriveAllowPolicy string = "redriveallowpolicy" | ||
RedriveAllowPolicyAWS string = "RedriveAllowPolicy" | ||
SqsManagedSseEnabled string = "sqsmanagedsseenabled" | ||
SqsManagedSseEnabledAWS string = "SqsManagedSseEnabled" | ||
ReceiveMessageWaitTimeSeconds string = "receivemessagewaittimeseconds" | ||
ReceiveMessageWaitTimeSecondsAWS string = "ReceiveMessageWaitTimeSeconds" | ||
) | ||
|
||
// Attr.Value | ||
const ( | ||
messageGroup string = "messagegroup" | ||
messageGroupAWS string = "messageGroup" | ||
|
||
perQueue string = "perqueue" | ||
perQueueAWS string = "perQueue" | ||
|
||
perMessageGroupID string = "permessagegroupid" | ||
perMessageGroupIDAWS string = "perMessageGroupId" | ||
) | ||
|
||
// toAwsAttribute maps attributes to its AWS values | ||
func toAwsAttribute(attrs map[string]string, ret map[string]string) { //nolint:gocyclo | ||
for k := range attrs { | ||
switch k { | ||
case SqsManagedSseEnabled: | ||
ret[SqsManagedSseEnabledAWS] = attrs[k] | ||
case RedriveAllowPolicy: | ||
ret[RedriveAllowPolicyAWS] = attrs[k] | ||
case FifoThroughputLimit: | ||
/* | ||
FifoThroughputLimit – Specifies whether the FIFO queue throughput quota applies to the entire queue or per message group. | ||
Valid values are perQueue and perMessageGroupId. The perMessageGroupId value is allowed only when the value for DeduplicationScope is messageGroup. | ||
*/ | ||
switch attrs[k] { | ||
case perQueue: | ||
ret[FifoThroughputLimitAWS] = perQueueAWS | ||
case perMessageGroupID: | ||
ret[FifoThroughputLimitAWS] = perMessageGroupIDAWS | ||
} | ||
case DeduplicationScope: | ||
// DeduplicationScope – Specifies whether message deduplication occurs at the | ||
// message group or queue level. Valid values are messageGroup and queue. | ||
if attrs[k] == messageGroup { | ||
ret[DeduplicationScopeAWS] = messageGroupAWS | ||
} | ||
case KmsDataKeyReusePeriodSeconds: | ||
ret[KmsDataKeyReusePeriodSecondsAWS] = attrs[k] | ||
case KmsMasterKeyID: | ||
ret[KmsMasterKeyIDAWS] = attrs[k] | ||
case ContentBasedDeduplication: | ||
ret[ContentBasedDeduplicationAWS] = attrs[k] | ||
case FifoQueue: | ||
ret[FifoQueueAWS] = attrs[k] | ||
case RedrivePolicy: | ||
ret[RedrivePolicyAWS] = attrs[k] | ||
case DelaySeconds: | ||
ret[DelaySecondsAWS] = attrs[k] | ||
case ApproximateNumberOfMessagesDelayed: | ||
ret[ApproximateNumberOfMessagesDelayedAWS] = attrs[k] | ||
case QueueArn: | ||
ret[QueueArnAWS] = attrs[k] | ||
case LastModifiedTimestamp: | ||
ret[LastModifiedTimestampAWS] = attrs[k] | ||
case Policy: | ||
ret[PolicyAWS] = attrs[k] | ||
case VisibilityTimeout: | ||
ret[VisibilityTimeoutAWS] = attrs[k] | ||
case MaximumMessageSize: | ||
ret[MaximumMessageSizeAWS] = attrs[k] | ||
case MessageRetentionPeriod: | ||
ret[MessageRetentionPeriodAWS] = attrs[k] | ||
case ApproximateNumberOfMessages: | ||
ret[ApproximateNumberOfMessagesAWS] = attrs[k] | ||
case ApproximateNumberOfMessagesNotVisible: | ||
ret[ApproximateNumberOfMessagesNotVisibleAWS] = attrs[k] | ||
case CreatedTimestamp: | ||
ret[CreatedTimestampAWS] = attrs[k] | ||
case ReceiveMessageWaitTimeSeconds: | ||
ret[ReceiveMessageWaitTimeSecondsAWS] = attrs[k] | ||
default: | ||
continue | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package sqsjobs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAttributes(t *testing.T) { | ||
m := make(map[string]string) | ||
m["policy"] = "foo" //nolint:goconst | ||
m["visibilitytimeout"] = "foo" | ||
m["maximummessagesize"] = "foo" | ||
m["messageretentionperiod"] = "foo" | ||
m["approximatenumberofmessages"] = "foo" | ||
m["approximatenumberofmessagesnotvisible"] = "foo" | ||
m["createdtimestamp"] = "foo" | ||
m["lastmodifiedtimestamp"] = "foo" | ||
m["queuearn"] = "foo" | ||
m["approximatenumberofmessagesdelayed"] = "foo" | ||
m["delayseconds"] = "foo" | ||
m["redrivepolicy"] = "foo" | ||
m["fifoqueue"] = "foo" | ||
m["contentbaseddeduplication"] = "foo" | ||
m["kmsmasterkeyid"] = "foo" | ||
m["kmsdatakeyreuseperiodseconds"] = "foo" | ||
m["fifothroughputlimit"] = "foo" | ||
m["redriveallowpolicy"] = "foo" | ||
m["sqsmanagedsseenabled"] = "foo" | ||
m["receivemessagewaittimeseconds"] = "foo" | ||
|
||
m["deduplicationscope"] = "messagegroup" | ||
m["fifothroughputlimit"] = "perqueue" | ||
|
||
m2 := make(map[string]string) | ||
toAwsAttribute(m, m2) | ||
cfg := Config{Attributes: m} | ||
cfg.InitDefault() | ||
|
||
require.Equal(t, "perQueue", m2["FifoThroughputLimit"]) | ||
require.Equal(t, "messageGroup", m2["DeduplicationScope"]) | ||
require.Equal(t, "foo", m2["Policy"]) | ||
require.Equal(t, "foo", m2["VisibilityTimeout"]) | ||
require.Equal(t, "foo", m2["MaximumMessageSize"]) | ||
require.Equal(t, "foo", m2["MessageRetentionPeriod"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessages"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessagesNotVisible"]) | ||
require.Equal(t, "foo", m2["CreatedTimestamp"]) | ||
require.Equal(t, "foo", m2["LastModifiedTimestamp"]) | ||
require.Equal(t, "foo", m2["QueueArn"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessagesDelayed"]) | ||
require.Equal(t, "foo", m2["RedrivePolicy"]) | ||
require.Equal(t, "foo", m2["FifoQueue"]) | ||
require.Equal(t, "foo", m2["ContentBasedDeduplication"]) | ||
require.Equal(t, "foo", m2["KmsMasterKeyId"]) | ||
require.Equal(t, "foo", m2["KmsDataKeyReusePeriodSeconds"]) | ||
require.Equal(t, "foo", m2["RedriveAllowPolicy"]) | ||
require.Equal(t, "foo", m2["SqsManagedSseEnabled"]) | ||
require.Equal(t, "foo", m2["ReceiveMessageWaitTimeSeconds"]) | ||
} | ||
|
||
func TestAttributes2(t *testing.T) { | ||
m := make(map[string]string) | ||
m["policy"] = "foo" | ||
m["visibilitytimeout"] = "foo" | ||
m["maximummessagesize"] = "foo" | ||
m["messageretentionperiod"] = "foo" | ||
m["approximatenumberofmessages"] = "foo" | ||
m["approximatenumberofmessagesnotvisible"] = "foo" | ||
m["createdtimestamp"] = "foo" | ||
m["lastmodifiedtimestamp"] = "foo" | ||
m["queuearn"] = "foo" | ||
m["approximatenumberofmessagesdelayed"] = "foo" | ||
m["delayseconds"] = "foo" | ||
m["redrivepolicy"] = "foo" | ||
m["fifoqueue"] = "foo" | ||
m["contentbaseddeduplication"] = "foo" | ||
m["kmsmasterkeyid"] = "foo" | ||
m["kmsdatakeyreuseperiodseconds"] = "foo" | ||
m["fifothroughputlimit"] = "foo" | ||
m["redriveallowpolicy"] = "foo" | ||
m["sqsmanagedsseenabled"] = "foo" | ||
m["receivemessagewaittimeseconds"] = "foo" | ||
|
||
m["deduplicationscope"] = "messagegroup" | ||
m["fifothroughputlimit"] = "permessagegroupid" | ||
|
||
m2 := make(map[string]string) | ||
toAwsAttribute(m, m2) | ||
cfg := Config{Attributes: m} | ||
cfg.InitDefault() | ||
|
||
require.Equal(t, "perMessageGroupId", m2["FifoThroughputLimit"]) | ||
require.Equal(t, "messageGroup", m2["DeduplicationScope"]) | ||
require.Equal(t, "foo", m2["Policy"]) | ||
require.Equal(t, "foo", m2["VisibilityTimeout"]) | ||
require.Equal(t, "foo", m2["MaximumMessageSize"]) | ||
require.Equal(t, "foo", m2["MessageRetentionPeriod"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessages"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessagesNotVisible"]) | ||
require.Equal(t, "foo", m2["CreatedTimestamp"]) | ||
require.Equal(t, "foo", m2["LastModifiedTimestamp"]) | ||
require.Equal(t, "foo", m2["QueueArn"]) | ||
require.Equal(t, "foo", m2["ApproximateNumberOfMessagesDelayed"]) | ||
require.Equal(t, "foo", m2["RedrivePolicy"]) | ||
require.Equal(t, "foo", m2["FifoQueue"]) | ||
require.Equal(t, "foo", m2["ContentBasedDeduplication"]) | ||
require.Equal(t, "foo", m2["KmsMasterKeyId"]) | ||
require.Equal(t, "foo", m2["KmsDataKeyReusePeriodSeconds"]) | ||
require.Equal(t, "foo", m2["RedriveAllowPolicy"]) | ||
require.Equal(t, "foo", m2["SqsManagedSseEnabled"]) | ||
require.Equal(t, "foo", m2["ReceiveMessageWaitTimeSeconds"]) | ||
} |
Oops, something went wrong.