Skip to content

Commit

Permalink
fix(tdhttp): (*tdhttp.TestApi).CmpJSONBody(nil) panicked
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed Sep 12, 2021
1 parent 13e0c61 commit 8a1c3c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions helpers/tdhttp/test_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ func (t *TestAPI) cmpMarshaledBody(
}
} else {
bodyType = reflect.TypeOf(expectedBody)
if bodyType == nil {
bodyType = types.Interface
}
}

// For unmarshaling below, body must be a pointer
Expand Down
10 changes: 10 additions & 0 deletions helpers/tdhttp/test_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ bingo%CR
}

mockT := tdutil.NewT("test")
td.CmpFalse(t,
tdhttp.NewTestAPI(mockT, mux).
NewJSONRequest("GET", "/mirror/json", json.RawMessage(`null`)).
CmpStatus(200).
CmpHeader(containsKey).
CmpJSONBody(nil).
Failed())
td.CmpEmpty(t, mockT.LogBuf())

mockT = tdutil.NewT("test")
td.CmpFalse(t,
tdhttp.NewTestAPI(mockT, mux).
NewJSONRequest("ZIP", "/any/json", requestBody).
Expand Down

0 comments on commit 8a1c3c4

Please sign in to comment.