@@ -22,31 +22,36 @@ func TestErrorObjectWritesExpectedErrorMessage(t *testing.T) {
2222
2323func TestMarshalErrorsWritesTheExpectedPayload (t * testing.T ) {
2424 var marshalErrorsTableTasts = []struct {
25- In []* ErrorObject
26- Out map [string ]interface {}
25+ Title string
26+ In []* ErrorObject
27+ Out map [string ]interface {}
2728 }{
28- { // This tests that given fields are turned into the appropriate JSON representation.
29- In : []* ErrorObject {{ID : "0" , Title : "Test title." , Detail : "Test detail" , Status : "400" , Code : "E1100" }},
29+ {
30+ Title : "TestFieldsAreSerializedAsNeeded" ,
31+ In : []* ErrorObject {{ID : "0" , Title : "Test title." , Detail : "Test detail" , Status : "400" , Code : "E1100" }},
3032 Out : map [string ]interface {}{"errors" : []interface {}{
3133 map [string ]interface {}{"id" : "0" , "title" : "Test title." , "detail" : "Test detail" , "status" : "400" , "code" : "E1100" },
3234 }},
3335 },
34- { // This tests that the `Meta` field is serialized properly.
35- In : []* ErrorObject {{Title : "Test title." , Detail : "Test detail" , Meta : & map [string ]interface {}{"key" : "val" }}},
36+ {
37+ Title : "TestMetaFieldIsSerializedProperly" ,
38+ In : []* ErrorObject {{Title : "Test title." , Detail : "Test detail" , Meta : & map [string ]interface {}{"key" : "val" }}},
3639 Out : map [string ]interface {}{"errors" : []interface {}{
3740 map [string ]interface {}{"title" : "Test title." , "detail" : "Test detail" , "meta" : map [string ]interface {}{"key" : "val" }},
3841 }},
3942 },
4043 }
4144 for _ , testRow := range marshalErrorsTableTasts {
42- buffer , output := bytes .NewBuffer (nil ), map [string ]interface {}{}
43- var writer io.Writer = buffer
45+ t .Run (testRow .Title , func (t * testing.T ) {
46+ buffer , output := bytes .NewBuffer (nil ), map [string ]interface {}{}
47+ var writer io.Writer = buffer
4448
45- _ = MarshalErrors (writer , testRow .In )
46- json .Unmarshal (buffer .Bytes (), & output )
49+ _ = MarshalErrors (writer , testRow .In )
50+ json .Unmarshal (buffer .Bytes (), & output )
4751
48- if ! reflect .DeepEqual (output , testRow .Out ) {
49- t .Fatalf ("Expected: \n %#v \n to equal: \n %#v" , output , testRow .Out )
50- }
52+ if ! reflect .DeepEqual (output , testRow .Out ) {
53+ t .Fatalf ("Expected: \n %#v \n to equal: \n %#v" , output , testRow .Out )
54+ }
55+ })
5156 }
5257}
0 commit comments