From a41127e5a6ca10b064c6136b01596e8246db3f9b Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Thu, 31 Jan 2019 12:39:13 -0800 Subject: [PATCH 1/4] Add S3 test event As seen in https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html --- events/s3.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/events/s3.go b/events/s3.go index a0641a3f..97f3f490 100644 --- a/events/s3.go +++ b/events/s3.go @@ -51,3 +51,11 @@ type S3Object struct { ETag string `json:"eTag"` Sequencer string `json:"sequencer"` } + +type S3TestEvent struct { + Service string `json:"Service"` + Event string `json:"Event"` + Time time.Time `json:"Time"` + RequestID string `json:"RequestId"` + HostID string `json:"HostId"` +} From 159433e693e45b42e9eaaf7edb9e4bfcba6719e3 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Mon, 4 Feb 2019 19:51:02 +0000 Subject: [PATCH 2/4] add Bucket sample event: ``` {"Service":"Amazon S3","Event":"s3:TestEvent","Time":"2019-02-04T19:34:46.985Z","Bucket":"bmoffatt","RequestId":"7BA1940DC6AF888B","HostId":"q1YDbiaMjllP0m+Lcy6cKKgxNrMLFJ9zCrZUFBqHGTG++0nXvnTDIGC7q2/QPAsJg86E8gI7y9U="} ``` --- events/s3.go | 1 + 1 file changed, 1 insertion(+) diff --git a/events/s3.go b/events/s3.go index 97f3f490..5af34931 100644 --- a/events/s3.go +++ b/events/s3.go @@ -54,6 +54,7 @@ type S3Object struct { type S3TestEvent struct { Service string `json:"Service"` + Bucket string `json:"Bucket"` Event string `json:"Event"` Time time.Time `json:"Time"` RequestID string `json:"RequestId"` From 356619f93e9de2bf8c50b9e7de9e4e0454ceff9b Mon Sep 17 00:00:00 2001 From: Moffatt Date: Tue, 19 Feb 2019 10:07:47 +0000 Subject: [PATCH 3/4] add test data for S3TestEvent --- events/s3_test.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/events/s3_test.go b/events/s3_test.go index 0d7f1dc0..2fc05410 100644 --- a/events/s3_test.go +++ b/events/s3_test.go @@ -12,24 +12,44 @@ import ( func TestS3EventMarshaling(t *testing.T) { // 1. read JSON from file - inputJson := readJsonFromFile(t, "./testdata/s3-event.json") + inputJSON := readJsonFromFile(t, "./testdata/s3-event.json") // 2. de-serialize into Go object var inputEvent S3Event - if err := json.Unmarshal(inputJson, &inputEvent); err != nil { + 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) + 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)) + assert.JSONEq(t, string(inputJSON), string(outputJSON)) } -func TestS3MarshalingMalformedJson(t *testing.T) { +func TestS3TestEventMarchaling(t *testing.T) { + inputJSON := []byte(`{ + "Service" :"Amazon S3", + "Event": "s3:TestEvent", + "Time": "2019-02-04T19:34:46.985Z", + "Bucket": "bmoffatt", + "RequestId": "7BA1940DC6AF888B", + "HostId": "q1YDbiaMjllP0m+Lcy6cKKgxNrMLFJ9zCrZUFBqHGTG++0nXvnTDIGC7q2/QPAsJg86E8gI7y9U=" + }`) + var inputEvent S3TestEvent + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { + t.Errorf("could not marshal event. details: %v", err) + } + outputJSON, err := json.Marshal(inputEvent) + if err != nil { + t.Errorf("could not marshal event. details: %v", err) + } + assert.JSONEq(t, string(inputJSON), string(outputJSON)) +} + +func TestS3MarshalingMalformedJSON(t *testing.T) { test.TestMalformedJson(t, S3Event{}) } From ab347d4ea97a1b50ead639fecde85625f7f7e13c Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 19 Feb 2019 10:15:01 +0000 Subject: [PATCH 4/4] Fix test typo Marchaling -> Marshaling --- events/s3_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/s3_test.go b/events/s3_test.go index 2fc05410..f1d45ea4 100644 --- a/events/s3_test.go +++ b/events/s3_test.go @@ -30,7 +30,7 @@ func TestS3EventMarshaling(t *testing.T) { assert.JSONEq(t, string(inputJSON), string(outputJSON)) } -func TestS3TestEventMarchaling(t *testing.T) { +func TestS3TestEventMarshaling(t *testing.T) { inputJSON := []byte(`{ "Service" :"Amazon S3", "Event": "s3:TestEvent",