-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudwatch_handler_test.go
50 lines (39 loc) · 1.21 KB
/
cloudwatch_handler_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
package g8_test
import (
"context"
"io"
"testing"
"github.com/aws/aws-lambda-go/events"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/JSainsburyPLC/g8"
)
func TestCloudWatchHandler_SingleMessage(t *testing.T) {
timesCalled := 0
resourceArn := "arn:aws:events:us-east-1:123456789012:rule/MyScheduledRule"
h := g8.CloudWatchHandler(func(c *g8.CloudWatchContext) (g8.LambdaResult, error) {
timesCalled++
assert.Equal(t, resourceArn, c.Event.Resources[0])
assert.NotEmpty(t, c.CorrelationID)
return "finished", nil
}, g8.HandlerConfig{Logger: zerolog.New(io.Discard)})
result, err := h(context.Background(), events.CloudWatchEvent{
Resources: []string{resourceArn},
})
assert.Nil(t, err)
assert.Equal(t, "finished", result)
assert.Equal(t, 1, timesCalled)
}
func TestCloudWatchHandler_HandlerError(t *testing.T) {
timesCalled := 0
handlerFunc := func(c *g8.CloudWatchContext) (g8.LambdaResult, error) {
timesCalled++
return nil, assert.AnError
}
h := g8.CloudWatchHandler(handlerFunc, g8.HandlerConfig{
Logger: zerolog.New(io.Discard),
})
_, err := h(context.Background(), events.CloudWatchEvent{})
assert.Equal(t, assert.AnError, err)
assert.Equal(t, 1, timesCalled)
}