-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamo_test.go
74 lines (59 loc) · 1.78 KB
/
dynamo_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package theta_test
import (
"context"
"encoding/json"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/phogolabs/theta"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/phogolabs/theta/fake"
)
var _ = Describe("DynamoHandler", func() {
var (
reactor *theta.DynamoHandler
handler *FakeEventHandler
)
BeforeEach(func() {
handler = &FakeEventHandler{}
reactor = &theta.DynamoHandler{
EventHandler: handler,
}
})
NewDynamoEvent := func(data map[string]events.DynamoDBAttributeValue) events.DynamoDBEvent {
return events.DynamoDBEvent{
Records: []events.DynamoDBEventRecord{
{
EventName: "INSERT",
EventSourceArn: "arn:aws:dynamodb:us-east-1:655141976367:table/notification-messages/stream/2019-07-11T10:10:31.424",
Change: events.DynamoDBStreamRecord{NewImage: data},
},
},
}
}
It("reacts on event successfully", func() {
attr := make(map[string]events.DynamoDBAttributeValue)
attr["id"] = events.NewStringAttribute("123")
kevent := NewDynamoEvent(attr)
Expect(reactor.HandleContext(context.TODO(), kevent)).To(Succeed())
Expect(handler.HandleContextCallCount()).To(Equal(1))
_, args := handler.HandleContextArgsForCall(0)
Expect(args.Event.Name).To(Equal("insert_notification_messages"))
type Row struct {
ID string `json:"id"`
}
row := &Row{}
Expect(json.Unmarshal(args.Body, row)).To(Succeed())
Expect(row.ID).To(Equal("123"))
})
Context("when the event handler fails", func() {
BeforeEach(func() {
handler.HandleContextReturns(fmt.Errorf("oh no"))
})
It("returns an error", func() {
attr := make(map[string]events.DynamoDBAttributeValue)
kevent := NewDynamoEvent(attr)
Expect(reactor.HandleContext(context.TODO(), kevent)).To(MatchError("oh no"))
})
})
})