Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Amazon MQ event structure #346

Merged
merged 4 commits into from Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions events/activemq.go
@@ -0,0 +1,30 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

package events

type ActiveMQEvent struct {
EventSource string `json:"eventSource"`
EventSourceARN string `json:"eventSourceArn"`
Messages []ActiveMQMessage `json:"messages"`
}

type ActiveMQMessage struct {
MessageID string `json:"messageID"`
MessageType string `json:"messageType"`
Timestamp int64 `json:"timestamp"`
DeliveryMode int `json:"deliveryMode"`
CorrelationID string `json:"correlationID"`
ReplyTo string `json:"replyTo"`
Destination ActiveMQDestination `json:"destination"`
Redelivered bool `json:"redelivered"`
Type string `json:"type"`
Expiration int64 `json:"expiration"`
Priority int `json:"priority"`
Data string `json:"data"`
bmoffatt marked this conversation as resolved.
Show resolved Hide resolved
BrokerInTime int64 `json:"brokerInTime"`
BrokerOutTime int64 `json:"brokerOutTime"`
}

type ActiveMQDestination struct {
PhysicalName string `json:"physicalName"`
}
46 changes: 46 additions & 0 deletions events/activemq_test.go
@@ -0,0 +1,46 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package events

import (
"encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
"github.com/stretchr/testify/assert"
)

func TestActiveMQEventMarshaling(t *testing.T) {
// 1. read JSON from file
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")

// 2. de-serialize into Go object
var inputEvent ActiveMQEvent
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// 3. Verify values populated into Go Object, at least one validation per data type
assert.Equal(t, "aws:mq", inputEvent.EventSource)
assert.Equal(t, "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", inputEvent.EventSourceARN)
assert.Equal(t, 1, len(inputEvent.Messages))

var message = inputEvent.Messages[0]
assert.Equal(t, "jms/text-message", message.MessageType)
assert.Equal(t, int64(1599863938941), message.Timestamp)
assert.Equal(t, 1, message.DeliveryMode)
assert.Equal(t, "testQueue", message.Destination.PhysicalName)
assert.Equal(t, false, message.Redelivered)

// 4. serialize to JSON
outputJson, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

// 5. check result
assert.JSONEq(t, string(inputJson), string(outputJson))
}

func TestActiveMQMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, ActiveMQEvent{})
}
24 changes: 24 additions & 0 deletions events/testdata/activemq-event.json
@@ -0,0 +1,24 @@
{
"eventSource": "aws:mq",
"eventSourceArn": "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5",
"messages": [
{
"messageID": "ID:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5-2.mq.us-west-2.amazonaws.com-34859-1598944546501-4:12:1:1:3",
"messageType": "jms/text-message",
"timestamp": 1599863938941,
"deliveryMode": 1,
"correlationID": "",
"replyTo": "null",
"destination": {
"physicalName": "testQueue"
},
"redelivered": false,
"type": "",
"expiration": 0,
"priority": 0,
"data": "RW50ZXIgc29tZSB0ZXh0IGhlcmUgZm9yIHRoZSBtZXNzYWdlIGJvZHkuLi4=",
"brokerInTime": 1599863938943,
"brokerOutTime": 1599863938944
}
]
}