Skip to content

Instantly share code, notes, and snippets.

@parsnips
Last active December 11, 2020 17:15
Show Gist options
  • Save parsnips/65a4c91affe57f0a003c59258834adc8 to your computer and use it in GitHub Desktop.
Save parsnips/65a4c91affe57f0a003c59258834adc8 to your computer and use it in GitHub Desktop.
diff --git a/cfn/handler/request_test.go b/cfn/handler/request_test.go
index f7728fd..7a5f015 100644
--- a/cfn/handler/request_test.go
+++ b/cfn/handler/request_test.go
@@ -63,3 +63,59 @@ func TestUnmarshal(t *testing.T) {
t.Errorf(diff)
}
}
+
+func TestNestedUnmarshal(t *testing.T) {
+ type Model struct {
+ Name *string
+ Version *float64
+ Detail map[string]interface{}
+ }
+
+ req := Request{
+ LogicalResourceID: "foo",
+ previousResourcePropertiesBody: []byte(`{"Name":"bar","Version":"0.1","Detail":{"Nested":{"Build":"57","IsProduction":"false"}}}`),
+ resourcePropertiesBody: []byte(`{"Name":"baz","Version":"2.3","Detail":{"Nested":{"Build":"69","IsProduction":"true"}}}`),
+ }
+
+ expectedPrevious := Model{
+ Name: aws.String("bar"),
+ Version: aws.Float64(0.1),
+ Detail: map[string]interface{}{
+ "Nested": map[string]interface{}{
+ "Build": aws.Int(57),
+ "IsProduction": aws.Bool(false),
+ },
+ },
+ }
+
+ expectedCurrent := Model{
+ Name: aws.String("baz"),
+ Version: aws.Float64(2.3),
+ Detail: map[string]interface{}{
+ "Nested": map[string]interface{}{
+ "Build": aws.Int(69),
+ "IsProduction": aws.Bool(true),
+ },
+ },
+ }
+
+ actual := Model{}
+
+ // Previous body
+ err := req.UnmarshalPrevious(&actual)
+ if err != nil {
+ t.Error(err)
+ }
+ if diff := cmp.Diff(actual, expectedPrevious); diff != "" {
+ t.Errorf(diff)
+ }
+
+ // Current body
+ err = req.Unmarshal(&actual)
+ if err != nil {
+ t.Error(err)
+ }
+ if diff := cmp.Diff(actual, expectedCurrent); diff != "" {
+ t.Errorf(diff)
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment