Skip to content

Commit

Permalink
http_assertions: Include msgAndArgs is some of the existing tests
Browse files Browse the repository at this point in the history
A mix of using and not using msgAndArgs will ensure that there is no
regression.
  • Loading branch information
arjunmahishi committed Feb 23, 2024
1 parent 135b468 commit 840f800
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions assert/http_assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func TestHTTPSuccess(t *testing.T) {
assert.True(mockT2.Failed())

mockT3 := new(testing.T)
assert.Equal(HTTPSuccess(mockT3, httpError, "GET", "/", nil), false)
assert.Equal(HTTPSuccess(
mockT3, httpError, "GET", "/", nil,
"was not expecting a failure here",
), false)
assert.True(mockT3.Failed())

mockT4 := new(testing.T)
Expand All @@ -58,7 +61,10 @@ func TestHTTPRedirect(t *testing.T) {
assert := New(t)

mockT1 := new(testing.T)
assert.Equal(HTTPRedirect(mockT1, httpOK, "GET", "/", nil), false)
assert.Equal(HTTPRedirect(
mockT1, httpOK, "GET", "/", nil,
"was expecting a 3xx status code. Got 200.",
), false)
assert.True(mockT1.Failed())

mockT2 := new(testing.T)
Expand All @@ -82,7 +88,10 @@ func TestHTTPError(t *testing.T) {
assert.True(mockT1.Failed())

mockT2 := new(testing.T)
assert.Equal(HTTPError(mockT2, httpRedirect, "GET", "/", nil), false)
assert.Equal(HTTPError(
mockT2, httpRedirect, "GET", "/", nil,
"Expected this request to error out. But it didn't",
), false)
assert.True(mockT2.Failed())

mockT3 := new(testing.T)
Expand All @@ -106,7 +115,10 @@ func TestHTTPStatusCode(t *testing.T) {
assert.True(mockT2.Failed())

mockT3 := new(testing.T)
assert.Equal(HTTPStatusCode(mockT3, httpError, "GET", "/", nil, http.StatusSwitchingProtocols), false)
assert.Equal(HTTPStatusCode(
mockT3, httpError, "GET", "/", nil, http.StatusSwitchingProtocols,
"Expected the status code to be %d", http.StatusSwitchingProtocols,
), false)
assert.True(mockT3.Failed())

mockT4 := new(testing.T)
Expand Down Expand Up @@ -174,7 +186,10 @@ func TestHttpBody(t *testing.T) {
assert.False(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))

assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!"))
assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World"))
assert.False(HTTPBodyNotContains(
mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World",
"Expected the request body to not contain 'World'. But it did.",
))
assert.True(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))

assert.True(HTTPBodyContains(mockT, httpReadBody, "GET", "/", nil, "hello"))
Expand Down

0 comments on commit 840f800

Please sign in to comment.