Browse Source

fix testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Bo-Yi Wu 9 years ago
parent
commit
787bff85e5
4 changed files with 16 additions and 16 deletions
  1. 6 6
      context_test.go
  2. 6 6
      logger_test.go
  3. 2 2
      middleware_test.go
  4. 2 2
      render/render_test.go

+ 6 - 6
context_test.go

@@ -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, w.Body.String(), "{\"foo\":\"bar\"}\n")
-	assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
+	assert.Equal(t, 201, w.Code)
+	assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
+	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, w.Body.String(), "{\"foo\":\"bar\"}\n")
-	assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/vnd.api+json")
+	assert.Equal(t, 201, w.Code)
+	assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
+	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

+ 6 - 6
logger_test.go

@@ -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, w.Body.String(), "{\"error\":\"this is an error\"}\n")
+	assert.Equal(t, 200, w.Code)
+	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, w.Body.String(), "{\"error\":\"no authorized\"}\n")
+	assert.Equal(t, 401, w.Code)
+	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, w.Body.String(), "hola!{\"error\":\"this is an error\"}\n")
+	assert.Equal(t, 500, w.Code)
+	assert.Equal(t, "hola!{\"error\":\"this is an error\"}", w.Body.String())
 }
 }
 
 
 func TestSkippingPaths(t *testing.T) {
 func TestSkippingPaths(t *testing.T) {

+ 2 - 2
middleware_test.go

@@ -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, 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, 400, w.Code)
+	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))
 }
 }

+ 2 - 2
render/render_test.go

@@ -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, w.Header().Get("Content-Type"), "application/json; charset=utf-8")
+	assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
+	assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
 }
 }
 
 
 func TestRenderIndentedJSON(t *testing.T) {
 func TestRenderIndentedJSON(t *testing.T) {