Skip to content

Commit

Permalink
service/sqs: Add batch checksum validation test
Browse files Browse the repository at this point in the history
Adds additional test of the SQS batch checksum validation.

V2 aws/aws-sdk-go-v2#239
  • Loading branch information
jasdel committed Dec 3, 2018
1 parent 88388f1 commit c540b23
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
5 changes: 2 additions & 3 deletions service/sqs/checksums.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ func verifySendMessageBatch(r *request.Request) {

in := r.Params.(*SendMessageBatchInput)
for _, entry := range in.Entries {
if e := entries[*entry.Id]; e != nil {
err := checksumsMatch(entry.MessageBody, e.MD5OfMessageBody)
if err != nil {
if e, ok := entries[*entry.Id]; ok {
if err := checksumsMatch(entry.MessageBody, e.MD5OfMessageBody); err != nil {
ids = append(ids, *e.MessageId)
}
}
Expand Down
46 changes: 46 additions & 0 deletions service/sqs/checksums_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,52 @@ func TestSendMessageBatchChecksum(t *testing.T) {
}
}

func TestSendMessageBatchChecksumFailed(t *testing.T) {
req, _ := svc.SendMessageBatchRequest(&sqs.SendMessageBatchInput{
Entries: []*sqs.SendMessageBatchRequestEntry{
{Id: aws.String("1"), MessageBody: aws.String("test")},
{Id: aws.String("2"), MessageBody: aws.String("test")},
{Id: aws.String("3"), MessageBody: aws.String("test")},
{Id: aws.String("4"), MessageBody: aws.String("test")},
},
})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageBatchOutput{
Failed: []*sqs.BatchResultErrorEntry{
{
Id: aws.String("1"),
Code: aws.String("test"),
Message: aws.String("test"),
SenderFault: aws.Bool(false),
},
{
Id: aws.String("2"),
Code: aws.String("test"),
Message: aws.String("test"),
SenderFault: aws.Bool(false),
},
{
Id: aws.String("3"),
Code: aws.String("test"),
Message: aws.String("test"),
SenderFault: aws.Bool(false),
},
{
Id: aws.String("4"),
Code: aws.String("test"),
Message: aws.String("test"),
SenderFault: aws.Bool(false),
},
},
}
})
if err := req.Send(); err != nil {
t.Errorf("expect no error, got %v", err)
}
}

func TestSendMessageBatchChecksumInvalid(t *testing.T) {
req, _ := svc.SendMessageBatchRequest(&sqs.SendMessageBatchInput{
Entries: []*sqs.SendMessageBatchRequestEntry{
Expand Down

0 comments on commit c540b23

Please sign in to comment.