@@ -12,66 +12,31 @@ import (
1212 "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
1313)
1414
15- func TestResponseMarshalJSON (t * testing.T ) {
15+ func TestMarshalJSON (t * testing.T ) {
1616 type Model struct {
1717 Name * encoding.String
1818 Version * encoding.Float
1919 }
2020
21- for _ , tt := range []struct {
22- name string
23- response response
24- expected string
25- }{
26- {
27- name : "updated failed" ,
28- response : response {
29- Message : "foo" ,
30- OperationStatus : handler .Failed ,
31- ResourceModel : Model {
32- Name : encoding .NewString ("Douglas" ),
33- Version : encoding .NewFloat (42.1 ),
34- },
35- ErrorCode : cloudformation .HandlerErrorCodeNotUpdatable ,
36- BearerToken : "xyzzy" ,
37- },
38- expected : `{"message":"foo","status":"FAILED","resourceModel":{"Name":"Douglas","Version":"42.1"},"errorCode":"NotUpdatable","bearerToken":"xyzzy","resourceModels":null}` ,
21+ r := response {
22+ Message : "foo" ,
23+ OperationStatus : handler .Success ,
24+ ResourceModel : Model {
25+ Name : encoding .NewString ("Douglas" ),
26+ Version : encoding .NewFloat (42.1 ),
3927 },
40- {
41- name : "list with 1 result" ,
42- response : response {
43- OperationStatus : handler .Success ,
44- ResourceModels : []interface {}{
45- Model {
46- Name : encoding .NewString ("Douglas" ),
47- Version : encoding .NewFloat (42.1 ),
48- },
49- },
50- BearerToken : "xyzzy" ,
51- },
52- expected : `{"status":"SUCCESS","bearerToken":"xyzzy","resourceModels":[{"Name":"Douglas","Version":"42.1"}]}` ,
53- },
54- {
55- name : "list with empty array" ,
56- response : response {
57- OperationStatus : handler .Success ,
58- ResourceModels : []interface {}{},
59- BearerToken : "xyzzy" ,
60- },
61- expected : `{"status":"SUCCESS","bearerToken":"xyzzy","resourceModels":[]}` ,
62- },
63- } {
64- t .Run (tt .name , func (t * testing.T ) {
28+ ErrorCode : cloudformation .HandlerErrorCodeNotUpdatable ,
29+ BearerToken : "xyzzy" ,
30+ }
6531
66- actual , err := json .Marshal (tt .response )
67- if err != nil {
68- t .Errorf ("Unexpected error marshaling response JSON: %s" , err )
69- }
32+ expected := `{"message":"foo","status":"SUCCESS","resourceModel":{"Name":"Douglas","Version":"42.1"},"errorCode":"NotUpdatable","bearerToken":"xyzzy"}`
7033
71- if diff := cmp .Diff (string (actual ), tt .expected ); diff != "" {
72- t .Errorf (diff )
73- }
74- })
34+ actual , err := json .Marshal (r )
35+ if err != nil {
36+ t .Errorf ("Unexpected error marshaling response JSON: %s" , err )
7537 }
7638
39+ if diff := cmp .Diff (string (actual ), expected ); diff != "" {
40+ t .Errorf (diff )
41+ }
7742}
0 commit comments