Skip to content

Commit

Permalink
Clean up CodePipeline Job Implementation (#382)
Browse files Browse the repository at this point in the history
* [BREAKING CHANGE] Clean up CodePipeline Job Implementation

* Incorrectly used "CodePipelineEvent"

* Fix original typo missed when moving to job

* Maintain backwards compatibility while making the ambiguity more clear

* go fmt

* Fix up a merge issue and stray input
  • Loading branch information
whithajess committed Jul 26, 2021
1 parent 99b35f2 commit ee817dd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
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
File renamed without changes.

0 comments on commit ee817dd

Please sign in to comment.