Skip to content

Commit

Permalink
[#4]: bug(attributes): case sensitive sqs attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rustatian authored Feb 9, 2022
2 parents a049f07 + 1e6a908 commit 58bc0b0
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 23 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/linux.yml
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
- ineffassign # Detects when assignments to existing variables are not used
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- noctx # finds sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- prealloc # Finds slice declarations that could potentially be preallocated
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
go test -v -race -cover -tags=debug ./...
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/aws/aws-sdk-go-v2/service/sqs v1.16.0
github.com/aws/smithy-go v1.10.0
github.com/goccy/go-json v0.9.4
github.com/google/uuid v1.3.0
github.com/roadrunner-server/api/v2 v2.8.0-rc.3
github.com/roadrunner-server/errors v1.1.1
github.com/roadrunner-server/sdk/v2 v2.8.0-rc.3
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.21.0
)

Expand All @@ -24,8 +24,12 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.9.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.14.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/roadrunner-server/tcplisten v1.1.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -511,6 +513,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
123 changes: 123 additions & 0 deletions sqsjobs/attributes.go
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
}
}
}
113 changes: 113 additions & 0 deletions sqsjobs/attributes_test.go
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"])
}
Loading

0 comments on commit 58bc0b0

Please sign in to comment.