Skip to content

Commit 31dd0f8

Browse files
committed
fix JSONBody response accepts string and []byte
1 parent fbd31d6 commit 31dd0f8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

response_expectation.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ func (exp *responseExpectation) JsonBody(object interface{}) ResponseExpectation
6767
return exp.Body(nil)
6868
}
6969

70+
switch t := object.(type) {
71+
case []byte:
72+
var object interface{}
73+
err := json.Unmarshal(t, &object)
74+
if err != nil {
75+
exp.t.Fatalf("response expectation failed: could not parse to json: %+v", object)
76+
}
77+
resData, _ := json.Marshal(object)
78+
return exp.Body(resData)
79+
case string:
80+
var object interface{}
81+
err := json.Unmarshal([]byte(t), &object)
82+
if err != nil {
83+
exp.t.Fatalf("response expectation failed: could not parse to json: %+v", object)
84+
}
85+
resData, _ := json.Marshal(object)
86+
return exp.Body(resData)
87+
}
88+
7089
jsonBody, err := json.Marshal(object)
7190
if err != nil {
7291
exp.t.Fatalf("response expectation failed: could not parse to json: %+v", object)

0 commit comments

Comments
 (0)