-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kevin Pike <kevipike@amazon.com>
- Loading branch information
Showing
4 changed files
with
135 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package handler | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
"github.com/google/go-cmp/cmp" | ||
|
||
"encoding/json" | ||
|
||
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/encoding" | ||
) | ||
|
||
func TestProgressEventMarshalJSON(t *testing.T) { | ||
type Model struct { | ||
Name *encoding.String | ||
Version *encoding.Float | ||
} | ||
|
||
for _, tt := range []struct { | ||
name string | ||
event ProgressEvent | ||
expected string | ||
}{ | ||
{ | ||
name: "not updatable", | ||
event: ProgressEvent{ | ||
Message: "foo", | ||
OperationStatus: Failed, | ||
ResourceModel: Model{ | ||
Name: encoding.NewString("Douglas"), | ||
Version: encoding.NewFloat(42.1), | ||
}, | ||
HandlerErrorCode: cloudformation.HandlerErrorCodeNotUpdatable, | ||
}, | ||
expected: `{"status":"FAILED","errorCode":"NotUpdatable","message":"foo","resourceModel":{"Name":"Douglas","Version":"42.1"},"resourceModels":null}`, | ||
}, | ||
{ | ||
name: "list with 1 result", | ||
event: ProgressEvent{ | ||
OperationStatus: Success, | ||
ResourceModels: []interface{}{ | ||
Model{ | ||
Name: encoding.NewString("Douglas"), | ||
Version: encoding.NewFloat(42.1), | ||
}, | ||
}, | ||
}, | ||
expected: `{"status":"SUCCESS","resourceModels":[{"Name":"Douglas","Version":"42.1"}]}`, | ||
}, | ||
{ | ||
name: "list with empty array", | ||
event: ProgressEvent{ | ||
OperationStatus: Success, | ||
ResourceModels: []interface{}{}, | ||
}, | ||
expected: `{"status":"SUCCESS","resourceModels":[]}`, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
actual, err := json.Marshal(tt.event) | ||
if err != nil { | ||
t.Errorf("Unexpected error marshaling event JSON: %s", err) | ||
} | ||
|
||
if diff := cmp.Diff(string(actual), tt.expected); diff != "" { | ||
t.Errorf(diff) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters