|
| 1 | +// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +package events |
| 3 | + |
| 4 | +import ( |
| 5 | + "encoding/json" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/aws/aws-lambda-go/events/test" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestActiveMQEventMarshaling(t *testing.T) { |
| 13 | + // 1. read JSON from file |
| 14 | + inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json") |
| 15 | + |
| 16 | + // 2. de-serialize into Go object |
| 17 | + var inputEvent ActiveMQEvent |
| 18 | + if err := json.Unmarshal(inputJson, &inputEvent); err != nil { |
| 19 | + t.Errorf("could not unmarshal event. details: %v", err) |
| 20 | + } |
| 21 | + |
| 22 | + // 3. Verify values populated into Go Object, at least one validation per data type |
| 23 | + assert.Equal(t, "aws:mq", inputEvent.EventSource) |
| 24 | + assert.Equal(t, "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", inputEvent.EventSourceARN) |
| 25 | + assert.Equal(t, 1, len(inputEvent.Messages)) |
| 26 | + |
| 27 | + var message = inputEvent.Messages[0] |
| 28 | + assert.Equal(t, "jms/text-message", message.MessageType) |
| 29 | + assert.Equal(t, int64(1599863938941), message.Timestamp) |
| 30 | + assert.Equal(t, 1, message.DeliveryMode) |
| 31 | + assert.Equal(t, "testQueue", message.Destination.PhysicalName) |
| 32 | + assert.Equal(t, false, message.Redelivered) |
| 33 | + |
| 34 | + // 4. serialize to JSON |
| 35 | + outputJson, err := json.Marshal(inputEvent) |
| 36 | + if err != nil { |
| 37 | + t.Errorf("could not marshal event. details: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + // 5. check result |
| 41 | + assert.JSONEq(t, string(inputJson), string(outputJson)) |
| 42 | +} |
| 43 | + |
| 44 | +func TestActiveMQMarshalingMalformedJson(t *testing.T) { |
| 45 | + test.TestMalformedJson(t, ActiveMQEvent{}) |
| 46 | +} |
0 commit comments