fix testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
97d310b55c
commit
787bff85e5
@ -358,9 +358,9 @@ func TestContextRenderJSON(t *testing.T) {
|
|||||||
|
|
||||||
c.JSON(201, H{"foo": "bar"})
|
c.JSON(201, H{"foo": "bar"})
|
||||||
|
|
||||||
assert.Equal(t, w.Code, 201)
|
assert.Equal(t, 201, w.Code)
|
||||||
assert.Equal(t, w.Body.String(), "{\"foo\":\"bar\"}\n")
|
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
|
||||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
|
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the response is serialized as JSON
|
// Tests that the response is serialized as JSON
|
||||||
@ -372,9 +372,9 @@ func TestContextRenderAPIJSON(t *testing.T) {
|
|||||||
c.Header("Content-Type", "application/vnd.api+json")
|
c.Header("Content-Type", "application/vnd.api+json")
|
||||||
c.JSON(201, H{"foo": "bar"})
|
c.JSON(201, H{"foo": "bar"})
|
||||||
|
|
||||||
assert.Equal(t, w.Code, 201)
|
assert.Equal(t, 201, w.Code)
|
||||||
assert.Equal(t, w.Body.String(), "{\"foo\":\"bar\"}\n")
|
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
|
||||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/vnd.api+json")
|
assert.Equal(t, "application/vnd.api+json", w.HeaderMap.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the response is serialized as JSON
|
// Tests that the response is serialized as JSON
|
||||||
|
@ -107,16 +107,16 @@ func TestErrorLogger(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/error")
|
w := performRequest(router, "GET", "/error")
|
||||||
assert.Equal(t, w.Code, 200)
|
assert.Equal(t, 200, w.Code)
|
||||||
assert.Equal(t, w.Body.String(), "{\"error\":\"this is an error\"}\n")
|
assert.Equal(t, "{\"error\":\"this is an error\"}", w.Body.String())
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/abort")
|
w = performRequest(router, "GET", "/abort")
|
||||||
assert.Equal(t, w.Code, 401)
|
assert.Equal(t, 401, w.Code)
|
||||||
assert.Equal(t, w.Body.String(), "{\"error\":\"no authorized\"}\n")
|
assert.Equal(t, "{\"error\":\"no authorized\"}", w.Body.String())
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/print")
|
w = performRequest(router, "GET", "/print")
|
||||||
assert.Equal(t, w.Code, 500)
|
assert.Equal(t, 500, w.Code)
|
||||||
assert.Equal(t, w.Body.String(), "hola!{\"error\":\"this is an error\"}\n")
|
assert.Equal(t, "hola!{\"error\":\"this is an error\"}", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkippingPaths(t *testing.T) {
|
func TestSkippingPaths(t *testing.T) {
|
||||||
|
@ -245,6 +245,6 @@ func TestMiddlewareWrite(t *testing.T) {
|
|||||||
|
|
||||||
w := performRequest(router, "GET", "/")
|
w := performRequest(router, "GET", "/")
|
||||||
|
|
||||||
assert.Equal(t, w.Code, 400)
|
assert.Equal(t, 400, w.Code)
|
||||||
assert.Equal(t, strings.Replace(w.Body.String(), " ", "", -1), strings.Replace("hola\n<map><foo>bar</foo></map>{\"foo\":\"bar\"}\n{\"foo\":\"bar\"}\nevent:test\ndata:message\n\n", " ", "", -1))
|
assert.Equal(t, strings.Replace("hola\n<map><foo>bar</foo></map>{\"foo\":\"bar\"}{\"foo\":\"bar\"}event:test\ndata:message\n\n", " ", "", -1), strings.Replace(w.Body.String(), " ", "", -1))
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ func TestRenderJSON(t *testing.T) {
|
|||||||
err := (JSON{data}).Render(w)
|
err := (JSON{data}).Render(w)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, w.Body.String(), "{\"foo\":\"bar\"}\n")
|
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
|
||||||
assert.Equal(t, w.Header().Get("Content-Type"), "application/json; charset=utf-8")
|
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderIndentedJSON(t *testing.T) {
|
func TestRenderIndentedJSON(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user