From e0b9a6cdf66d7efee52d0e1e4d67e56f835b1195 Mon Sep 17 00:00:00 2001 From: shirakiya Date: Sat, 22 May 2021 11:02:58 +0900 Subject: [PATCH 1/2] add IoT 1-Click event (#371) --- events/iot_1_click.go | 34 ++++++++++++++++++++++++++ events/iot_1_click_test.go | 34 ++++++++++++++++++++++++++ events/testdata/iot-1-click-event.json | 29 ++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 events/iot_1_click.go create mode 100644 events/iot_1_click_test.go create mode 100644 events/testdata/iot-1-click-event.json diff --git a/events/iot_1_click.go b/events/iot_1_click.go new file mode 100644 index 00000000..b2e0d844 --- /dev/null +++ b/events/iot_1_click.go @@ -0,0 +1,34 @@ +// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +package events + +// IoTOneClickEvent represents a click event published by clicking button type +// device. +type IoTOneClickEvent struct { + DeviceEvent IoTOneClickDeviceEvent `json:"deviceEvent"` + DeviceInfo IoTOneClickDeviceInfo `json:"deviceInfo"` + PlacementInfo IoTOneClickPlacementInfo `json:"placementInfo"` +} + +type IoTOneClickDeviceEvent struct { + ButtonClicked IoTOneClickButtonClicked `json:"buttonClicked"` +} + +type IoTOneClickButtonClicked struct { + ClickType string `json:"clickType"` + ReportedTime string `json:"reportedTime"` +} + +type IoTOneClickDeviceInfo struct { + Attributes map[string]string `json:"attributes"` + Type string `json:"type"` + DeviceID string `json:"deviceId"` + RemainingLife float64 `json:"remainingLife"` +} + +type IoTOneClickPlacementInfo struct { + ProjectName string `json:"projectName"` + PlacementName string `json:"placementName"` + Attributes map[string]string `json:"attributes"` + Devices map[string]string `json:"devices"` +} diff --git a/events/iot_1_click_test.go b/events/iot_1_click_test.go new file mode 100644 index 00000000..ffff3a13 --- /dev/null +++ b/events/iot_1_click_test.go @@ -0,0 +1,34 @@ +// Copyright 2017 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 TestIoTOneClickEventMalformedJson(t *testing.T) { + + // 1. read JSON from file + inputJson := test.ReadJSONFromFile(t, "./testdata/iot-1-click-event.json") + + // 2. de-serialize into Go object + var inputEvent IoTOneClickEvent + if err := json.Unmarshal(inputJson, &inputEvent); err != nil { + t.Errorf("could not unmarshal event. details: %v", err) + } + + // 3. serialize to JSON + outputJson, err := json.Marshal(inputEvent) + if err != nil { + t.Errorf("could not marshal event. details: %v", err) + } + // 4. check result + assert.JSONEq(t, string(inputJson), string(outputJson)) +} + +func TestIoTOneClickEventMarshaling(t *testing.T) { + test.TestMalformedJson(t, IoTOneClickEvent{}) +} diff --git a/events/testdata/iot-1-click-event.json b/events/testdata/iot-1-click-event.json new file mode 100644 index 00000000..d1c324a0 --- /dev/null +++ b/events/testdata/iot-1-click-event.json @@ -0,0 +1,29 @@ +{ + "deviceEvent": { + "buttonClicked": { + "clickType": "SINGLE", + "reportedTime": "2018-05-04T23:26:33.747Z" + } + }, + "deviceInfo": { + "attributes": { + "key3": "value3", + "key1": "value1", + "key4": "value4" + }, + "type": "button", + "deviceId": "G030PMXXXXXXXXXX", + "remainingLife": 5.00 + }, + "placementInfo": { + "projectName": "test", + "placementName": "myPlacement", + "attributes": { + "location": "Seattle", + "equipment": "printer" + }, + "devices": { + "myButton": "G030PMXXXXXXXXXX" + } + } +} From 5d6413264f82afaa7587b56e3f09f1422c898c68 Mon Sep 17 00:00:00 2001 From: john-pacer <81990832+john-pacer@users.noreply.github.com> Date: Fri, 21 May 2021 21:39:29 -0500 Subject: [PATCH 2/2] Typo in NewHandler Function Description (#374) Co-authored-by: Bryan Moffatt --- lambda/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/handler.go b/lambda/handler.go index f6f931c1..39b8d6d8 100644 --- a/lambda/handler.go +++ b/lambda/handler.go @@ -76,7 +76,7 @@ func validateReturns(handler reflect.Type) error { } // NewHandler creates a base lambda handler from the given handler function. The -// returned Handler performs JSON deserialization and deserialization, and +// returned Handler performs JSON serialization and deserialization, and // delegates to the input handler function. The handler function parameter must // satisfy the rules documented by Start. If handlerFunc is not a valid // handler, the returned Handler simply reports the validation error.