@@ -22,31 +22,36 @@ func TestErrorObjectWritesExpectedErrorMessage(t *testing.T) {
22
22
23
23
func TestMarshalErrorsWritesTheExpectedPayload (t * testing.T ) {
24
24
var marshalErrorsTableTasts = []struct {
25
- In []* ErrorObject
26
- Out map [string ]interface {}
25
+ Title string
26
+ In []* ErrorObject
27
+ Out map [string ]interface {}
27
28
}{
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" }},
30
32
Out : map [string ]interface {}{"errors" : []interface {}{
31
33
map [string ]interface {}{"id" : "0" , "title" : "Test title." , "detail" : "Test detail" , "status" : "400" , "code" : "E1100" },
32
34
}},
33
35
},
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" }}},
36
39
Out : map [string ]interface {}{"errors" : []interface {}{
37
40
map [string ]interface {}{"title" : "Test title." , "detail" : "Test detail" , "meta" : map [string ]interface {}{"key" : "val" }},
38
41
}},
39
42
},
40
43
}
41
44
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
44
48
45
- _ = MarshalErrors (writer , testRow .In )
46
- json .Unmarshal (buffer .Bytes (), & output )
49
+ _ = MarshalErrors (writer , testRow .In )
50
+ json .Unmarshal (buffer .Bytes (), & output )
47
51
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
+ })
51
56
}
52
57
}
0 commit comments