Skip to content

Clean up CodePipeline Job Implementation #382

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 8 commits into from
Jul 26, 2021
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
6 changes: 6 additions & 0 deletions events/codepipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package events

// CodePipelineJob has been incorrectly assigned as CodePipelineEvent
// - https://github.com/aws/aws-lambda-go/issues/244
// This maintains backwards compatability until a v2 release
type CodePipelineEvent = CodePipelineJobEvent
4 changes: 2 additions & 2 deletions events/codepipeline_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package events

// CodePipelineEvent contains data from an event sent from AWS Codepipeline
type CodePipelineEvent struct {
// CodePipelineJobEvent contains data from an event sent from AWS CodePipeline
type CodePipelineJobEvent struct {
CodePipelineJob CodePipelineJob `json:"CodePipeline.job"`
}

Expand Down
38 changes: 38 additions & 0 deletions events/codepipeline_job_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package events

import (
"encoding/json"
"io/ioutil"
"testing"

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

func TestCodePipeLineJobEventMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/codepipeline-job-event.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

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

// serialize to json
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 TestCodePipelineJobEventMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, CodePipelineJobEvent{})
}
2 changes: 1 addition & 1 deletion events/codepipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestCodePipeLineEventMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/codepipline-event.json")
inputJSON, err := ioutil.ReadFile("./testdata/codepipeline-job-event.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down