Skip to content

Add S3 test event #163

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

Merged
merged 4 commits into from
Feb 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions events/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ type S3Object struct {
ETag string `json:"eTag"`
Sequencer string `json:"sequencer"`
}

type S3TestEvent struct {
Service string `json:"Service"`
Bucket string `json:"Bucket"`
Event string `json:"Event"`
Time time.Time `json:"Time"`
RequestID string `json:"RequestId"`
HostID string `json:"HostId"`
}
30 changes: 25 additions & 5 deletions events/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 TestS3TestEventMarshaling(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{})
}