-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subscriber): add ability to consume items from queue (#101)
This adds a handler to process SQS messages. We were previously dumping only subscription requests into the queue. This commit additional makes it so that any request recognized by the handler can also be consumed via the queue.
- Loading branch information
Showing
3 changed files
with
100 additions
and
2 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
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,74 @@ | ||
package subscriber_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/google/go-cmp/cmp" | ||
|
||
"github.com/observeinc/aws-sam-testing/handler/handlertest" | ||
"github.com/observeinc/aws-sam-testing/handler/subscriber" | ||
) | ||
|
||
func TestHandleSQS(t *testing.T) { | ||
t.Parallel() | ||
|
||
testcases := []struct { | ||
Event events.SQSEvent | ||
Expect events.SQSEventResponse | ||
}{ | ||
{ | ||
Event: events.SQSEvent{ | ||
Records: []events.SQSMessage{ | ||
{ | ||
MessageId: "invalid request", | ||
Body: "", | ||
}, | ||
}, | ||
}, | ||
Expect: events.SQSEventResponse{ | ||
BatchItemFailures: []events.SQSBatchItemFailure{ | ||
{ItemIdentifier: "invalid request"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Event: events.SQSEvent{ | ||
Records: []events.SQSMessage{ | ||
{ | ||
MessageId: "ok", | ||
Body: "{\"subscribe\": {\"logGroups\":[{\"logGroupName\":\"/aws/hello\"}]}}", | ||
}, | ||
}, | ||
}, | ||
Expect: events.SQSEventResponse{}, | ||
}, | ||
} | ||
|
||
for i, tt := range testcases { | ||
tt := tt | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
s, err := subscriber.New(&subscriber.Config{ | ||
CloudWatchLogsClient: &handlertest.CloudWatchLogsClient{}, | ||
FilterName: "test", | ||
LogGroupNamePrefixes: []string{"*"}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, err := s.HandleSQS(context.Background(), tt.Event) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if diff := cmp.Diff(resp, tt.Expect); diff != "" { | ||
t.Error(diff) | ||
} | ||
}) | ||
} | ||
} |