@@ -12,66 +12,31 @@ import (
12
12
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
13
13
)
14
14
15
- func TestResponseMarshalJSON (t * testing.T ) {
15
+ func TestMarshalJSON (t * testing.T ) {
16
16
type Model struct {
17
17
Name * encoding.String
18
18
Version * encoding.Float
19
19
}
20
20
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 ),
39
27
},
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
+ }
65
31
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"}`
70
33
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 )
75
37
}
76
38
39
+ if diff := cmp .Diff (string (actual ), expected ); diff != "" {
40
+ t .Errorf (diff )
41
+ }
77
42
}
0 commit comments