mirror of https://github.com/gin-gonic/gin.git
update assert param(expect, actual) position (#1177)
This commit is contained in:
parent
7e5aff8ea7
commit
eeb57848ca
286
context_test.go
286
context_test.go
|
@ -180,14 +180,14 @@ func TestContextSetGet(t *testing.T) {
|
|||
c.Set("foo", "bar")
|
||||
|
||||
value, err := c.Get("foo")
|
||||
assert.Equal(t, value, "bar")
|
||||
assert.Equal(t, "bar", value)
|
||||
assert.True(t, err)
|
||||
|
||||
value, err = c.Get("foo2")
|
||||
assert.Nil(t, value)
|
||||
assert.False(t, err)
|
||||
|
||||
assert.Equal(t, c.MustGet("foo"), "bar")
|
||||
assert.Equal(t, "bar", c.MustGet("foo"))
|
||||
assert.Panics(t, func() { c.MustGet("no_exist") })
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ func TestContextGetString(t *testing.T) {
|
|||
func TestContextSetGetBool(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.Set("bool", true)
|
||||
assert.Equal(t, true, c.GetBool("bool"))
|
||||
assert.True(t, c.GetBool("bool"))
|
||||
}
|
||||
|
||||
func TestContextGetInt(t *testing.T) {
|
||||
|
@ -338,26 +338,26 @@ func TestContextQuery(t *testing.T) {
|
|||
|
||||
value, ok := c.GetQuery("foo")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "bar")
|
||||
assert.Equal(t, c.DefaultQuery("foo", "none"), "bar")
|
||||
assert.Equal(t, c.Query("foo"), "bar")
|
||||
assert.Equal(t, "bar", value)
|
||||
assert.Equal(t, "bar", c.DefaultQuery("foo", "none"))
|
||||
assert.Equal(t, "bar", c.Query("foo"))
|
||||
|
||||
value, ok = c.GetQuery("page")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "10")
|
||||
assert.Equal(t, c.DefaultQuery("page", "0"), "10")
|
||||
assert.Equal(t, c.Query("page"), "10")
|
||||
assert.Equal(t, "10", value)
|
||||
assert.Equal(t, "10", c.DefaultQuery("page", "0"))
|
||||
assert.Equal(t, "10", c.Query("page"))
|
||||
|
||||
value, ok = c.GetQuery("id")
|
||||
assert.True(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Equal(t, c.DefaultQuery("id", "nada"), "")
|
||||
assert.Empty(t, c.DefaultQuery("id", "nada"))
|
||||
assert.Empty(t, c.Query("id"))
|
||||
|
||||
value, ok = c.GetQuery("NoKey")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Equal(t, c.DefaultQuery("NoKey", "nada"), "nada")
|
||||
assert.Equal(t, "nada", c.DefaultQuery("NoKey", "nada"))
|
||||
assert.Empty(t, c.Query("NoKey"))
|
||||
|
||||
// postform should not mess
|
||||
|
@ -373,29 +373,29 @@ func TestContextQueryAndPostForm(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("POST", "/?both=GET&id=main&id=omit&array[]=first&array[]=second", body)
|
||||
c.Request.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
|
||||
assert.Equal(t, c.DefaultPostForm("foo", "none"), "bar")
|
||||
assert.Equal(t, c.PostForm("foo"), "bar")
|
||||
assert.Equal(t, "bar", c.DefaultPostForm("foo", "none"))
|
||||
assert.Equal(t, "bar", c.PostForm("foo"))
|
||||
assert.Empty(t, c.Query("foo"))
|
||||
|
||||
value, ok := c.GetPostForm("page")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "11")
|
||||
assert.Equal(t, c.DefaultPostForm("page", "0"), "11")
|
||||
assert.Equal(t, c.PostForm("page"), "11")
|
||||
assert.Equal(t, c.Query("page"), "")
|
||||
assert.Equal(t, "11", value)
|
||||
assert.Equal(t, "11", c.DefaultPostForm("page", "0"))
|
||||
assert.Equal(t, "11", c.PostForm("page"))
|
||||
assert.Empty(t, c.Query("page"))
|
||||
|
||||
value, ok = c.GetPostForm("both")
|
||||
assert.True(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Empty(t, c.PostForm("both"))
|
||||
assert.Equal(t, c.DefaultPostForm("both", "nothing"), "")
|
||||
assert.Equal(t, c.Query("both"), "GET")
|
||||
assert.Empty(t, c.DefaultPostForm("both", "nothing"))
|
||||
assert.Equal(t, "GET", c.Query("both"), "GET")
|
||||
|
||||
value, ok = c.GetQuery("id")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "main")
|
||||
assert.Equal(t, c.DefaultPostForm("id", "000"), "000")
|
||||
assert.Equal(t, c.Query("id"), "main")
|
||||
assert.Equal(t, "main", value)
|
||||
assert.Equal(t, "000", c.DefaultPostForm("id", "000"))
|
||||
assert.Equal(t, "main", c.Query("id"))
|
||||
assert.Empty(t, c.PostForm("id"))
|
||||
|
||||
value, ok = c.GetQuery("NoKey")
|
||||
|
@ -404,8 +404,8 @@ func TestContextQueryAndPostForm(t *testing.T) {
|
|||
value, ok = c.GetPostForm("NoKey")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Equal(t, c.DefaultPostForm("NoKey", "nada"), "nada")
|
||||
assert.Equal(t, c.DefaultQuery("NoKey", "nothing"), "nothing")
|
||||
assert.Equal(t, "nada", c.DefaultPostForm("NoKey", "nada"))
|
||||
assert.Equal(t, "nothing", c.DefaultQuery("NoKey", "nothing"))
|
||||
assert.Empty(t, c.PostForm("NoKey"))
|
||||
assert.Empty(t, c.Query("NoKey"))
|
||||
|
||||
|
@ -417,11 +417,11 @@ func TestContextQueryAndPostForm(t *testing.T) {
|
|||
Array []string `form:"array[]"`
|
||||
}
|
||||
assert.NoError(t, c.Bind(&obj))
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, obj.ID, "main")
|
||||
assert.Equal(t, obj.Page, 11)
|
||||
assert.Equal(t, obj.Both, "")
|
||||
assert.Equal(t, obj.Array, []string{"first", "second"})
|
||||
assert.Equal(t, "bar", obj.Foo, "bar")
|
||||
assert.Equal(t, "main", obj.ID, "main")
|
||||
assert.Equal(t, 11, obj.Page, 11)
|
||||
assert.Empty(t, obj.Both)
|
||||
assert.Equal(t, []string{"first", "second"}, obj.Array)
|
||||
|
||||
values, ok := c.GetQueryArray("array[]")
|
||||
assert.True(t, ok)
|
||||
|
@ -456,37 +456,37 @@ func TestContextPostFormMultipart(t *testing.T) {
|
|||
BlankTime time.Time `form:"blank_time" time_format:"02/01/2006 15:04"`
|
||||
}
|
||||
assert.NoError(t, c.Bind(&obj))
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, obj.Bar, "10")
|
||||
assert.Equal(t, obj.BarAsInt, 10)
|
||||
assert.Equal(t, obj.Array, []string{"first", "second"})
|
||||
assert.Equal(t, obj.ID, "")
|
||||
assert.Equal(t, obj.TimeLocal.Format("02/01/2006 15:04"), "31/12/2016 14:55")
|
||||
assert.Equal(t, obj.TimeLocal.Location(), time.Local)
|
||||
assert.Equal(t, obj.TimeUTC.Format("02/01/2006 15:04"), "31/12/2016 14:55")
|
||||
assert.Equal(t, obj.TimeUTC.Location(), time.UTC)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, "10", obj.Bar)
|
||||
assert.Equal(t, 10, obj.BarAsInt)
|
||||
assert.Equal(t, []string{"first", "second"}, obj.Array)
|
||||
assert.Empty(t, obj.ID)
|
||||
assert.Equal(t, "31/12/2016 14:55", obj.TimeLocal.Format("02/01/2006 15:04"))
|
||||
assert.Equal(t, time.Local, obj.TimeLocal.Location())
|
||||
assert.Equal(t, "31/12/2016 14:55", obj.TimeUTC.Format("02/01/2006 15:04"))
|
||||
assert.Equal(t, time.UTC, obj.TimeUTC.Location())
|
||||
loc, _ := time.LoadLocation("Asia/Tokyo")
|
||||
assert.Equal(t, obj.TimeLocation.Format("02/01/2006 15:04"), "31/12/2016 14:55")
|
||||
assert.Equal(t, obj.TimeLocation.Location(), loc)
|
||||
assert.Equal(t, "31/12/2016 14:55", obj.TimeLocation.Format("02/01/2006 15:04"))
|
||||
assert.Equal(t, loc, obj.TimeLocation.Location())
|
||||
assert.True(t, obj.BlankTime.IsZero())
|
||||
|
||||
value, ok := c.GetQuery("foo")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Empty(t, c.Query("bar"))
|
||||
assert.Equal(t, c.DefaultQuery("id", "nothing"), "nothing")
|
||||
assert.Equal(t, "nothing", c.DefaultQuery("id", "nothing"))
|
||||
|
||||
value, ok = c.GetPostForm("foo")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "bar")
|
||||
assert.Equal(t, c.PostForm("foo"), "bar")
|
||||
assert.Equal(t, "bar", value)
|
||||
assert.Equal(t, "bar", c.PostForm("foo"))
|
||||
|
||||
value, ok = c.GetPostForm("array")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, value, "first")
|
||||
assert.Equal(t, c.PostForm("array"), "first")
|
||||
assert.Equal(t, "first", value)
|
||||
assert.Equal(t, "first", c.PostForm("array"))
|
||||
|
||||
assert.Equal(t, c.DefaultPostForm("bar", "nothing"), "10")
|
||||
assert.Equal(t, "10", c.DefaultPostForm("bar", "nothing"))
|
||||
|
||||
value, ok = c.GetPostForm("id")
|
||||
assert.True(t, ok)
|
||||
|
@ -497,7 +497,7 @@ func TestContextPostFormMultipart(t *testing.T) {
|
|||
value, ok = c.GetPostForm("nokey")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, value)
|
||||
assert.Equal(t, c.DefaultPostForm("nokey", "nothing"), "nothing")
|
||||
assert.Equal(t, "nothing", c.DefaultPostForm("nokey", "nothing"))
|
||||
|
||||
values, ok := c.GetPostFormArray("array")
|
||||
assert.True(t, ok)
|
||||
|
@ -519,13 +519,13 @@ func TestContextPostFormMultipart(t *testing.T) {
|
|||
func TestContextSetCookie(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.SetCookie("user", "gin", 1, "/", "localhost", true, true)
|
||||
assert.Equal(t, c.Writer.Header().Get("Set-Cookie"), "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure")
|
||||
assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure", c.Writer.Header().Get("Set-Cookie"))
|
||||
}
|
||||
|
||||
func TestContextSetCookiePathEmpty(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.SetCookie("user", "gin", 1, "", "localhost", true, true)
|
||||
assert.Equal(t, c.Writer.Header().Get("Set-Cookie"), "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure")
|
||||
assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure", c.Writer.Header().Get("Set-Cookie"))
|
||||
}
|
||||
|
||||
func TestContextGetCookie(t *testing.T) {
|
||||
|
@ -533,17 +533,17 @@ func TestContextGetCookie(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("GET", "/get", nil)
|
||||
c.Request.Header.Set("Cookie", "user=gin")
|
||||
cookie, _ := c.Cookie("user")
|
||||
assert.Equal(t, cookie, "gin")
|
||||
assert.Equal(t, "gin", cookie)
|
||||
|
||||
_, err := c.Cookie("nokey")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestContextBodyAllowedForStatus(t *testing.T) {
|
||||
assert.Equal(t, false, bodyAllowedForStatus(102))
|
||||
assert.Equal(t, false, bodyAllowedForStatus(204))
|
||||
assert.Equal(t, false, bodyAllowedForStatus(304))
|
||||
assert.Equal(t, true, bodyAllowedForStatus(500))
|
||||
assert.False(t, false, bodyAllowedForStatus(102))
|
||||
assert.False(t, false, bodyAllowedForStatus(204))
|
||||
assert.False(t, false, bodyAllowedForStatus(304))
|
||||
assert.True(t, true, bodyAllowedForStatus(500))
|
||||
}
|
||||
|
||||
type TestPanicRender struct {
|
||||
|
@ -589,7 +589,7 @@ func TestContextRenderNoContentJSON(t *testing.T) {
|
|||
c.JSON(204, H{"foo": "bar"})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ func TestContextRenderNoContentAPIJSON(t *testing.T) {
|
|||
c.JSON(204, H{"foo": "bar"})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/vnd.api+json")
|
||||
}
|
||||
|
||||
|
@ -628,7 +628,7 @@ func TestContextRenderIndentedJSON(t *testing.T) {
|
|||
|
||||
c.IndentedJSON(201, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}", w.Body.String())
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ func TestContextRenderNoContentIndentedJSON(t *testing.T) {
|
|||
c.IndentedJSON(204, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
|
@ -654,9 +654,9 @@ func TestContextRenderSecureJSON(t *testing.T) {
|
|||
router.SecureJsonPrefix("&&&START&&&")
|
||||
c.SecureJSON(201, []string{"foo", "bar"})
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "&&&START&&&[\"foo\",\"bar\"]")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "&&&START&&&[\"foo\",\"bar\"]", w.Body.String())
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no Custom JSON is rendered if code is 204
|
||||
|
@ -667,8 +667,8 @@ func TestContextRenderNoContentSecureJSON(t *testing.T) {
|
|||
c.SecureJSON(204, []string{"foo", "bar"})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that the response executes the templates
|
||||
|
@ -681,9 +681,9 @@ func TestContextRenderHTML(t *testing.T) {
|
|||
|
||||
c.HTML(201, "t", H{"name": "alexandernyquist"})
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "Hello alexandernyquist")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "Hello alexandernyquist", w.Body.String())
|
||||
assert.Equal(t, "text/html; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no HTML is rendered if code is 204
|
||||
|
@ -696,8 +696,8 @@ func TestContextRenderNoContentHTML(t *testing.T) {
|
|||
c.HTML(204, "t", H{"name": "alexandernyquist"})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "text/html; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextXML tests that the response is serialized as XML
|
||||
|
@ -708,9 +708,9 @@ func TestContextRenderXML(t *testing.T) {
|
|||
|
||||
c.XML(201, H{"foo": "bar"})
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "<map><foo>bar</foo></map>")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/xml; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "<map><foo>bar</foo></map>", w.Body.String())
|
||||
assert.Equal(t, "application/xml; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no XML is rendered if code is 204
|
||||
|
@ -721,8 +721,8 @@ func TestContextRenderNoContentXML(t *testing.T) {
|
|||
c.XML(204, H{"foo": "bar"})
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/xml; charset=utf-8")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "application/xml; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextString tests that the response is returned
|
||||
|
@ -733,9 +733,9 @@ func TestContextRenderString(t *testing.T) {
|
|||
|
||||
c.String(201, "test %s %d", "string", 2)
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "test string 2")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "test string 2", w.Body.String())
|
||||
assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no String is rendered if code is 204
|
||||
|
@ -746,8 +746,8 @@ func TestContextRenderNoContentString(t *testing.T) {
|
|||
c.String(204, "test %s %d", "string", 2)
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextString tests that the response is returned
|
||||
|
@ -759,9 +759,9 @@ func TestContextRenderHTMLString(t *testing.T) {
|
|||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
c.String(201, "<html>%s %d</html>", "string", 3)
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "<html>string 3</html>")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "<html>string 3</html>", w.Body.String())
|
||||
assert.Equal(t, "text/html; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no HTML String is rendered if code is 204
|
||||
|
@ -773,8 +773,8 @@ func TestContextRenderNoContentHTMLString(t *testing.T) {
|
|||
c.String(204, "<html>%s %d</html>", "string", 3)
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "text/html; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextData tests that the response can be written from `bytesting`
|
||||
|
@ -785,9 +785,9 @@ func TestContextRenderData(t *testing.T) {
|
|||
|
||||
c.Data(201, "text/csv", []byte(`foo,bar`))
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Body.String(), "foo,bar")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/csv")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "foo,bar", w.Body.String())
|
||||
assert.Equal(t, "text/csv", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Tests that no Custom Data is rendered if code is 204
|
||||
|
@ -798,8 +798,8 @@ func TestContextRenderNoContentData(t *testing.T) {
|
|||
c.Data(204, "text/csv", []byte(`foo,bar`))
|
||||
|
||||
assert.Equal(t, 204, w.Code)
|
||||
assert.Equal(t, "", w.Body.String())
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/csv")
|
||||
assert.Empty(t, w.Body.String())
|
||||
assert.Equal(t, "text/csv", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestContextRenderSSE(t *testing.T) {
|
||||
|
@ -826,9 +826,9 @@ func TestContextRenderFile(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("GET", "/", nil)
|
||||
c.File("./gin.go")
|
||||
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "func New() *Engine {")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
|
||||
assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestContextRenderYAML tests that the response is serialized as YAML
|
||||
|
@ -839,9 +839,9 @@ func TestContextRenderYAML(t *testing.T) {
|
|||
|
||||
c.YAML(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/x-yaml; charset=utf-8")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "foo: bar\n", w.Body.String())
|
||||
assert.Equal(t, "application/x-yaml; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestContextHeaders(t *testing.T) {
|
||||
|
@ -849,13 +849,13 @@ func TestContextHeaders(t *testing.T) {
|
|||
c.Header("Content-Type", "text/plain")
|
||||
c.Header("X-Custom", "value")
|
||||
|
||||
assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/plain")
|
||||
assert.Equal(t, c.Writer.Header().Get("X-Custom"), "value")
|
||||
assert.Equal(t, "text/plain", c.Writer.Header().Get("Content-Type"))
|
||||
assert.Equal(t, "value", c.Writer.Header().Get("X-Custom"))
|
||||
|
||||
c.Header("Content-Type", "text/html")
|
||||
c.Header("X-Custom", "")
|
||||
|
||||
assert.Equal(t, c.Writer.Header().Get("Content-Type"), "text/html")
|
||||
assert.Equal(t, "text/html", c.Writer.Header().Get("Content-Type"))
|
||||
_, exist := c.Writer.Header()["X-Custom"]
|
||||
assert.False(t, exist)
|
||||
}
|
||||
|
@ -871,8 +871,8 @@ func TestContextRenderRedirectWithRelativePath(t *testing.T) {
|
|||
|
||||
c.Redirect(301, "/path")
|
||||
c.Writer.WriteHeaderNow()
|
||||
assert.Equal(t, w.Code, 301)
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path")
|
||||
assert.Equal(t, 301, w.Code)
|
||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||
}
|
||||
|
||||
func TestContextRenderRedirectWithAbsolutePath(t *testing.T) {
|
||||
|
@ -883,8 +883,8 @@ func TestContextRenderRedirectWithAbsolutePath(t *testing.T) {
|
|||
c.Redirect(302, "http://google.com")
|
||||
c.Writer.WriteHeaderNow()
|
||||
|
||||
assert.Equal(t, w.Code, 302)
|
||||
assert.Equal(t, w.Header().Get("Location"), "http://google.com")
|
||||
assert.Equal(t, 302, w.Code)
|
||||
assert.Equal(t, "http://google.com", w.Header().Get("Location"))
|
||||
}
|
||||
|
||||
func TestContextRenderRedirectWith201(t *testing.T) {
|
||||
|
@ -895,8 +895,8 @@ func TestContextRenderRedirectWith201(t *testing.T) {
|
|||
c.Redirect(201, "/resource")
|
||||
c.Writer.WriteHeaderNow()
|
||||
|
||||
assert.Equal(t, w.Code, 201)
|
||||
assert.Equal(t, w.Header().Get("Location"), "/resource")
|
||||
assert.Equal(t, 201, w.Code)
|
||||
assert.Equal(t, "/resource", w.Header().Get("Location"))
|
||||
}
|
||||
|
||||
func TestContextRenderRedirectAll(t *testing.T) {
|
||||
|
@ -977,8 +977,8 @@ func TestContextNegotiationFormat(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("POST", "", nil)
|
||||
|
||||
assert.Panics(t, func() { c.NegotiateFormat() })
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEJSON)
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEHTML, MIMEJSON), MIMEHTML)
|
||||
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML))
|
||||
assert.Equal(t, MIMEHTML, c.NegotiateFormat(MIMEHTML, MIMEJSON))
|
||||
}
|
||||
|
||||
func TestContextNegotiationFormatWithAccept(t *testing.T) {
|
||||
|
@ -986,9 +986,9 @@ func TestContextNegotiationFormatWithAccept(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("POST", "/", nil)
|
||||
c.Request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEXML)
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEXML, MIMEHTML), MIMEHTML)
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEJSON), "")
|
||||
assert.Equal(t, MIMEXML, c.NegotiateFormat(MIMEJSON, MIMEXML))
|
||||
assert.Equal(t, MIMEHTML, c.NegotiateFormat(MIMEXML, MIMEHTML))
|
||||
assert.Empty(t, c.NegotiateFormat(MIMEJSON))
|
||||
}
|
||||
|
||||
func TestContextNegotiationFormatCustum(t *testing.T) {
|
||||
|
@ -999,9 +999,9 @@ func TestContextNegotiationFormatCustum(t *testing.T) {
|
|||
c.Accepted = nil
|
||||
c.SetAccepted(MIMEJSON, MIMEXML)
|
||||
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEJSON, MIMEXML), MIMEJSON)
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEXML, MIMEHTML), MIMEXML)
|
||||
assert.Equal(t, c.NegotiateFormat(MIMEJSON), MIMEJSON)
|
||||
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML))
|
||||
assert.Equal(t, MIMEXML, c.NegotiateFormat(MIMEXML, MIMEHTML))
|
||||
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON))
|
||||
}
|
||||
|
||||
func TestContextIsAborted(t *testing.T) {
|
||||
|
@ -1027,9 +1027,9 @@ func TestContextAbortWithStatus(t *testing.T) {
|
|||
c.index = 4
|
||||
c.AbortWithStatus(401)
|
||||
|
||||
assert.Equal(t, c.index, abortIndex)
|
||||
assert.Equal(t, c.Writer.Status(), 401)
|
||||
assert.Equal(t, w.Code, 401)
|
||||
assert.Equal(t, abortIndex, c.index)
|
||||
assert.Equal(t, 401, c.Writer.Status())
|
||||
assert.Equal(t, 401, w.Code)
|
||||
assert.True(t, c.IsAborted())
|
||||
}
|
||||
|
||||
|
@ -1049,13 +1049,13 @@ func TestContextAbortWithStatusJSON(t *testing.T) {
|
|||
|
||||
c.AbortWithStatusJSON(415, in)
|
||||
|
||||
assert.Equal(t, c.index, abortIndex)
|
||||
assert.Equal(t, c.Writer.Status(), 415)
|
||||
assert.Equal(t, w.Code, 415)
|
||||
assert.Equal(t, abortIndex, c.index)
|
||||
assert.Equal(t, 415, c.Writer.Status())
|
||||
assert.Equal(t, 415, w.Code)
|
||||
assert.True(t, c.IsAborted())
|
||||
|
||||
contentType := w.Header().Get("Content-Type")
|
||||
assert.Equal(t, contentType, "application/json; charset=utf-8")
|
||||
assert.Equal(t, "application/json; charset=utf-8", contentType)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(w.Body)
|
||||
|
@ -1069,7 +1069,7 @@ func TestContextError(t *testing.T) {
|
|||
|
||||
c.Error(errors.New("first error"))
|
||||
assert.Len(t, c.Errors, 1)
|
||||
assert.Equal(t, c.Errors.String(), "Error #01: first error\n")
|
||||
assert.Equal(t, "Error #01: first error\n", c.Errors.String())
|
||||
|
||||
c.Error(&Error{
|
||||
Err: errors.New("second error"),
|
||||
|
@ -1078,13 +1078,13 @@ func TestContextError(t *testing.T) {
|
|||
})
|
||||
assert.Len(t, c.Errors, 2)
|
||||
|
||||
assert.Equal(t, c.Errors[0].Err, errors.New("first error"))
|
||||
assert.Equal(t, errors.New("first error"), c.Errors[0].Err)
|
||||
assert.Nil(t, c.Errors[0].Meta)
|
||||
assert.Equal(t, c.Errors[0].Type, ErrorTypePrivate)
|
||||
assert.Equal(t, ErrorTypePrivate, c.Errors[0].Type)
|
||||
|
||||
assert.Equal(t, c.Errors[1].Err, errors.New("second error"))
|
||||
assert.Equal(t, c.Errors[1].Meta, "some data 2")
|
||||
assert.Equal(t, c.Errors[1].Type, ErrorTypePublic)
|
||||
assert.Equal(t, errors.New("second error"), c.Errors[1].Err)
|
||||
assert.Equal(t, "some data 2", c.Errors[1].Meta)
|
||||
assert.Equal(t, ErrorTypePublic, c.Errors[1].Type)
|
||||
|
||||
assert.Equal(t, c.Errors.Last(), c.Errors[1])
|
||||
|
||||
|
@ -1102,12 +1102,12 @@ func TestContextTypedError(t *testing.T) {
|
|||
c.Error(errors.New("interno 0")).SetType(ErrorTypePrivate)
|
||||
|
||||
for _, err := range c.Errors.ByType(ErrorTypePublic) {
|
||||
assert.Equal(t, err.Type, ErrorTypePublic)
|
||||
assert.Equal(t, ErrorTypePublic, err.Type)
|
||||
}
|
||||
for _, err := range c.Errors.ByType(ErrorTypePrivate) {
|
||||
assert.Equal(t, err.Type, ErrorTypePrivate)
|
||||
assert.Equal(t, ErrorTypePrivate, err.Type)
|
||||
}
|
||||
assert.Equal(t, c.Errors.Errors(), []string{"externo 0", "interno 0"})
|
||||
assert.Equal(t, []string{"externo 0", "interno 0"}, c.Errors.Errors())
|
||||
}
|
||||
|
||||
func TestContextAbortWithError(t *testing.T) {
|
||||
|
@ -1116,8 +1116,8 @@ func TestContextAbortWithError(t *testing.T) {
|
|||
|
||||
c.AbortWithError(401, errors.New("bad input")).SetMeta("some input")
|
||||
|
||||
assert.Equal(t, w.Code, 401)
|
||||
assert.Equal(t, c.index, abortIndex)
|
||||
assert.Equal(t, 401, w.Code)
|
||||
assert.Equal(t, abortIndex, c.index)
|
||||
assert.True(t, c.IsAborted())
|
||||
}
|
||||
|
||||
|
@ -1148,7 +1148,7 @@ func TestContextClientIP(t *testing.T) {
|
|||
|
||||
// no port
|
||||
c.Request.RemoteAddr = "50.50.50.50"
|
||||
assert.Equal(t, "", c.ClientIP())
|
||||
assert.Empty(t, c.ClientIP())
|
||||
}
|
||||
|
||||
func TestContextContentType(t *testing.T) {
|
||||
|
@ -1156,7 +1156,7 @@ func TestContextContentType(t *testing.T) {
|
|||
c.Request, _ = http.NewRequest("POST", "/", nil)
|
||||
c.Request.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
assert.Equal(t, c.ContentType(), "application/json")
|
||||
assert.Equal(t, "application/json", c.ContentType())
|
||||
}
|
||||
|
||||
func TestContextAutoBindJSON(t *testing.T) {
|
||||
|
@ -1169,8 +1169,8 @@ func TestContextAutoBindJSON(t *testing.T) {
|
|||
Bar string `json:"bar"`
|
||||
}
|
||||
assert.NoError(t, c.Bind(&obj))
|
||||
assert.Equal(t, obj.Bar, "foo")
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Empty(t, c.Errors)
|
||||
}
|
||||
|
||||
|
@ -1186,9 +1186,9 @@ func TestContextBindWithJSON(t *testing.T) {
|
|||
Bar string `json:"bar"`
|
||||
}
|
||||
assert.NoError(t, c.BindJSON(&obj))
|
||||
assert.Equal(t, obj.Bar, "foo")
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, w.Body.Len(), 0)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, 0, w.Body.Len())
|
||||
}
|
||||
|
||||
func TestContextBindWithQuery(t *testing.T) {
|
||||
|
@ -1224,7 +1224,7 @@ func TestContextBadAutoBind(t *testing.T) {
|
|||
|
||||
assert.Empty(t, obj.Bar)
|
||||
assert.Empty(t, obj.Foo)
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.Equal(t, 400, w.Code)
|
||||
assert.True(t, c.IsAborted())
|
||||
}
|
||||
|
||||
|
@ -1238,8 +1238,8 @@ func TestContextAutoShouldBindJSON(t *testing.T) {
|
|||
Bar string `json:"bar"`
|
||||
}
|
||||
assert.NoError(t, c.ShouldBind(&obj))
|
||||
assert.Equal(t, obj.Bar, "foo")
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Empty(t, c.Errors)
|
||||
}
|
||||
|
||||
|
@ -1255,9 +1255,9 @@ func TestContextShouldBindWithJSON(t *testing.T) {
|
|||
Bar string `json:"bar"`
|
||||
}
|
||||
assert.NoError(t, c.ShouldBindJSON(&obj))
|
||||
assert.Equal(t, obj.Bar, "foo")
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, w.Body.Len(), 0)
|
||||
assert.Equal(t, "foo", obj.Bar)
|
||||
assert.Equal(t, "bar", obj.Foo)
|
||||
assert.Equal(t, 0, w.Body.Len())
|
||||
}
|
||||
|
||||
func TestContextShouldBindWithQuery(t *testing.T) {
|
||||
|
@ -1307,7 +1307,7 @@ func TestContextGolangContext(t *testing.T) {
|
|||
assert.Nil(t, c.Value("foo"))
|
||||
|
||||
c.Set("foo", "bar")
|
||||
assert.Equal(t, c.Value("foo"), "bar")
|
||||
assert.Equal(t, "bar", c.Value("foo"))
|
||||
assert.Nil(t, c.Value(1))
|
||||
}
|
||||
|
||||
|
@ -1339,7 +1339,7 @@ func TestGetRequestHeaderValue(t *testing.T) {
|
|||
c.Request.Header.Set("Gin-Version", "1.0.0")
|
||||
|
||||
assert.Equal(t, "1.0.0", c.GetHeader("Gin-Version"))
|
||||
assert.Equal(t, "", c.GetHeader("Connection"))
|
||||
assert.Empty(t, c.GetHeader("Connection"))
|
||||
}
|
||||
|
||||
func TestContextGetRawData(t *testing.T) {
|
||||
|
|
|
@ -170,12 +170,12 @@ func TestCreateEngine(t *testing.T) {
|
|||
// router.LoadHTMLGlob("*.testtmpl")
|
||||
// r := router.HTMLRender.(render.HTMLDebug)
|
||||
// assert.Empty(t, r.Files)
|
||||
// assert.Equal(t, r.Glob, "*.testtmpl")
|
||||
// assert.Equal(t, "*.testtmpl", r.Glob)
|
||||
//
|
||||
// router.LoadHTMLFiles("index.html.testtmpl", "login.html.testtmpl")
|
||||
// r = router.HTMLRender.(render.HTMLDebug)
|
||||
// assert.Empty(t, r.Glob)
|
||||
// assert.Equal(t, r.Files, []string{"index.html", "login.html"})
|
||||
// assert.Equal(t, []string{"index.html", "login.html"}, r.Files)
|
||||
// SetMode(TestMode)
|
||||
// }
|
||||
|
||||
|
|
|
@ -82,21 +82,21 @@ func TestLogger(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestColorForMethod(t *testing.T) {
|
||||
assert.Equal(t, colorForMethod("GET"), string([]byte{27, 91, 57, 55, 59, 52, 52, 109}), "get should be blue")
|
||||
assert.Equal(t, colorForMethod("POST"), string([]byte{27, 91, 57, 55, 59, 52, 54, 109}), "post should be cyan")
|
||||
assert.Equal(t, colorForMethod("PUT"), string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), "put should be yellow")
|
||||
assert.Equal(t, colorForMethod("DELETE"), string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), "delete should be red")
|
||||
assert.Equal(t, colorForMethod("PATCH"), string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), "patch should be green")
|
||||
assert.Equal(t, colorForMethod("HEAD"), string([]byte{27, 91, 57, 55, 59, 52, 53, 109}), "head should be magenta")
|
||||
assert.Equal(t, colorForMethod("OPTIONS"), string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), "options should be white")
|
||||
assert.Equal(t, colorForMethod("TRACE"), string([]byte{27, 91, 48, 109}), "trace is not defined and should be the reset color")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 52, 109}), colorForMethod("GET"), "get should be blue")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 54, 109}), colorForMethod("POST"), "post should be cyan")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), colorForMethod("PUT"), "put should be yellow")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), colorForMethod("DELETE"), "delete should be red")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), colorForMethod("PATCH"), "patch should be green")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 53, 109}), colorForMethod("HEAD"), "head should be magenta")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), colorForMethod("OPTIONS"), "options should be white")
|
||||
assert.Equal(t, string([]byte{27, 91, 48, 109}), colorForMethod("TRACE"), "trace is not defined and should be the reset color")
|
||||
}
|
||||
|
||||
func TestColorForStatus(t *testing.T) {
|
||||
assert.Equal(t, colorForStatus(200), string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), "2xx should be green")
|
||||
assert.Equal(t, colorForStatus(301), string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), "3xx should be white")
|
||||
assert.Equal(t, colorForStatus(404), string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), "4xx should be yellow")
|
||||
assert.Equal(t, colorForStatus(2), string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), "other things should be red")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), colorForStatus(200), "2xx should be green")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), colorForStatus(301), "3xx should be white")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), colorForStatus(404), "4xx should be yellow")
|
||||
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), colorForStatus(2), "other things should be red")
|
||||
}
|
||||
|
||||
func TestErrorLogger(t *testing.T) {
|
||||
|
|
16
mode_test.go
16
mode_test.go
|
@ -17,21 +17,21 @@ func init() {
|
|||
}
|
||||
|
||||
func TestSetMode(t *testing.T) {
|
||||
assert.Equal(t, ginMode, testCode)
|
||||
assert.Equal(t, Mode(), TestMode)
|
||||
assert.Equal(t, testCode, ginMode)
|
||||
assert.Equal(t, TestMode, Mode())
|
||||
os.Unsetenv(ENV_GIN_MODE)
|
||||
|
||||
SetMode(DebugMode)
|
||||
assert.Equal(t, ginMode, debugCode)
|
||||
assert.Equal(t, Mode(), DebugMode)
|
||||
assert.Equal(t, debugCode, ginMode)
|
||||
assert.Equal(t, DebugMode, Mode())
|
||||
|
||||
SetMode(ReleaseMode)
|
||||
assert.Equal(t, ginMode, releaseCode)
|
||||
assert.Equal(t, Mode(), ReleaseMode)
|
||||
assert.Equal(t, releaseCode, ginMode)
|
||||
assert.Equal(t, ReleaseMode, Mode())
|
||||
|
||||
SetMode(TestMode)
|
||||
assert.Equal(t, ginMode, testCode)
|
||||
assert.Equal(t, Mode(), TestMode)
|
||||
assert.Equal(t, testCode, ginMode)
|
||||
assert.Equal(t, TestMode, Mode())
|
||||
|
||||
assert.Panics(t, func() { SetMode("unknown") })
|
||||
}
|
||||
|
|
|
@ -67,8 +67,8 @@ var cleanTests = []struct {
|
|||
|
||||
func TestPathClean(t *testing.T) {
|
||||
for _, test := range cleanTests {
|
||||
assert.Equal(t, cleanPath(test.path), test.result)
|
||||
assert.Equal(t, cleanPath(test.result), test.result)
|
||||
assert.Equal(t, test.result, cleanPath(test.path))
|
||||
assert.Equal(t, test.result, cleanPath(test.result))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestPanicInHandler(t *testing.T) {
|
|||
// RUN
|
||||
w := performRequest(router, "GET", "/recovery")
|
||||
// TEST
|
||||
assert.Equal(t, w.Code, 500)
|
||||
assert.Equal(t, 500, w.Code)
|
||||
assert.Contains(t, buffer.String(), "GET /recovery")
|
||||
assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")
|
||||
assert.Contains(t, buffer.String(), "TestPanicInHandler")
|
||||
|
@ -39,5 +39,5 @@ func TestPanicWithAbort(t *testing.T) {
|
|||
// RUN
|
||||
w := performRequest(router, "GET", "/recovery")
|
||||
// TEST
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.Equal(t, 400, w.Code)
|
||||
}
|
||||
|
|
|
@ -20,15 +20,15 @@ func TestRouterGroupBasic(t *testing.T) {
|
|||
group.Use(func(c *Context) {})
|
||||
|
||||
assert.Len(t, group.Handlers, 2)
|
||||
assert.Equal(t, group.BasePath(), "/hola")
|
||||
assert.Equal(t, group.engine, router)
|
||||
assert.Equal(t, "/hola", group.BasePath())
|
||||
assert.Equal(t, router, group.engine)
|
||||
|
||||
group2 := group.Group("manu")
|
||||
group2.Use(func(c *Context) {}, func(c *Context) {})
|
||||
|
||||
assert.Len(t, group2.Handlers, 4)
|
||||
assert.Equal(t, group2.BasePath(), "/hola/manu")
|
||||
assert.Equal(t, group2.engine, router)
|
||||
assert.Equal(t, "/hola/manu", group2.BasePath())
|
||||
assert.Equal(t, router, group2.engine)
|
||||
}
|
||||
|
||||
func TestRouterGroupBasicHandle(t *testing.T) {
|
||||
|
@ -44,10 +44,10 @@ func TestRouterGroupBasicHandle(t *testing.T) {
|
|||
func performRequestInGroup(t *testing.T, method string) {
|
||||
router := New()
|
||||
v1 := router.Group("v1", func(c *Context) {})
|
||||
assert.Equal(t, v1.BasePath(), "/v1")
|
||||
assert.Equal(t, "/v1", v1.BasePath())
|
||||
|
||||
login := v1.Group("/login/", func(c *Context) {}, func(c *Context) {})
|
||||
assert.Equal(t, login.BasePath(), "/v1/login/")
|
||||
assert.Equal(t, "/v1/login/", login.BasePath())
|
||||
|
||||
handler := func(c *Context) {
|
||||
c.String(400, "the method was %s and index %d", c.Request.Method, c.index)
|
||||
|
@ -80,12 +80,12 @@ func performRequestInGroup(t *testing.T, method string) {
|
|||
}
|
||||
|
||||
w := performRequest(router, method, "/v1/login/test")
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.Equal(t, w.Body.String(), "the method was "+method+" and index 3")
|
||||
assert.Equal(t, 400, w.Code)
|
||||
assert.Equal(t, "the method was "+method+" and index 3", w.Body.String())
|
||||
|
||||
w = performRequest(router, method, "/v1/test")
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.Equal(t, w.Body.String(), "the method was "+method+" and index 1")
|
||||
assert.Equal(t, 400, w.Code)
|
||||
assert.Equal(t, "the method was "+method+" and index 1", w.Body.String())
|
||||
}
|
||||
|
||||
func TestRouterGroupInvalidStatic(t *testing.T) {
|
||||
|
|
124
routes_test.go
124
routes_test.go
|
@ -36,7 +36,7 @@ func testRouteOK(method string, t *testing.T) {
|
|||
|
||||
w := performRequest(r, method, "/test")
|
||||
assert.True(t, passed)
|
||||
assert.Equal(t, w.Code, http.StatusOK)
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
performRequest(r, method, "/test2")
|
||||
assert.True(t, passedAny)
|
||||
|
@ -53,7 +53,7 @@ func testRouteNotOK(method string, t *testing.T) {
|
|||
w := performRequest(router, method, "/test")
|
||||
|
||||
assert.False(t, passed)
|
||||
assert.Equal(t, w.Code, http.StatusNotFound)
|
||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||
}
|
||||
|
||||
// TestSingleRouteOK tests that POST route is correctly invoked.
|
||||
|
@ -74,7 +74,7 @@ func testRouteNotOK2(method string, t *testing.T) {
|
|||
w := performRequest(router, method, "/test")
|
||||
|
||||
assert.False(t, passed)
|
||||
assert.Equal(t, w.Code, http.StatusMethodNotAllowed)
|
||||
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
||||
}
|
||||
|
||||
func TestRouterMethod(t *testing.T) {
|
||||
|
@ -93,8 +93,8 @@ func TestRouterMethod(t *testing.T) {
|
|||
|
||||
w := performRequest(router, "PUT", "/hey")
|
||||
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, w.Body.String(), "called")
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Equal(t, "called", w.Body.String())
|
||||
}
|
||||
|
||||
func TestRouterGroupRouteOK(t *testing.T) {
|
||||
|
@ -143,43 +143,43 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
|
|||
router.PUT("/path4/", func(c *Context) {})
|
||||
|
||||
w := performRequest(router, "GET", "/path/")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path")
|
||||
assert.Equal(t, w.Code, 301)
|
||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||
assert.Equal(t, 301, w.Code)
|
||||
|
||||
w = performRequest(router, "GET", "/path2")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path2/")
|
||||
assert.Equal(t, w.Code, 301)
|
||||
assert.Equal(t, "/path2/", w.Header().Get("Location"))
|
||||
assert.Equal(t, 301, w.Code)
|
||||
|
||||
w = performRequest(router, "POST", "/path3/")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path3")
|
||||
assert.Equal(t, w.Code, 307)
|
||||
assert.Equal(t, "/path3", w.Header().Get("Location"))
|
||||
assert.Equal(t, 307, w.Code)
|
||||
|
||||
w = performRequest(router, "PUT", "/path4")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path4/")
|
||||
assert.Equal(t, w.Code, 307)
|
||||
assert.Equal(t, "/path4/", w.Header().Get("Location"))
|
||||
assert.Equal(t, 307, w.Code)
|
||||
|
||||
w = performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
||||
w = performRequest(router, "GET", "/path2/")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
||||
w = performRequest(router, "POST", "/path3")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
||||
w = performRequest(router, "PUT", "/path4/")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
||||
router.RedirectTrailingSlash = false
|
||||
|
||||
w = performRequest(router, "GET", "/path/")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
w = performRequest(router, "GET", "/path2")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
w = performRequest(router, "POST", "/path3/")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
w = performRequest(router, "PUT", "/path4")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
}
|
||||
|
||||
func TestRouteRedirectFixedPath(t *testing.T) {
|
||||
|
@ -193,20 +193,20 @@ func TestRouteRedirectFixedPath(t *testing.T) {
|
|||
router.POST("/Path4/", func(c *Context) {})
|
||||
|
||||
w := performRequest(router, "GET", "/PATH")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/path")
|
||||
assert.Equal(t, w.Code, 301)
|
||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||
assert.Equal(t, 301, w.Code)
|
||||
|
||||
w = performRequest(router, "GET", "/path2")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/Path2")
|
||||
assert.Equal(t, w.Code, 301)
|
||||
assert.Equal(t, "/Path2", w.Header().Get("Location"))
|
||||
assert.Equal(t, 301, w.Code)
|
||||
|
||||
w = performRequest(router, "POST", "/path3")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/PATH3")
|
||||
assert.Equal(t, w.Code, 307)
|
||||
assert.Equal(t, "/PATH3", w.Header().Get("Location"))
|
||||
assert.Equal(t, 307, w.Code)
|
||||
|
||||
w = performRequest(router, "POST", "/path4")
|
||||
assert.Equal(t, w.Header().Get("Location"), "/Path4/")
|
||||
assert.Equal(t, w.Code, 307)
|
||||
assert.Equal(t, "/Path4/", w.Header().Get("Location"))
|
||||
assert.Equal(t, 307, w.Code)
|
||||
}
|
||||
|
||||
// TestContextParamsGet tests that a parameter can be parsed from the URL.
|
||||
|
@ -236,10 +236,10 @@ func TestRouteParamsByName(t *testing.T) {
|
|||
|
||||
w := performRequest(router, "GET", "/test/john/smith/is/super/great")
|
||||
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, name, "john")
|
||||
assert.Equal(t, lastName, "smith")
|
||||
assert.Equal(t, wild, "/is/super/great")
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Equal(t, "john", name)
|
||||
assert.Equal(t, "smith", lastName)
|
||||
assert.Equal(t, "/is/super/great", wild)
|
||||
}
|
||||
|
||||
// TestHandleStaticFile - ensure the static file handles properly
|
||||
|
@ -265,15 +265,15 @@ func TestRouteStaticFile(t *testing.T) {
|
|||
w2 := performRequest(router, "GET", "/result")
|
||||
|
||||
assert.Equal(t, w, w2)
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, w.Body.String(), "Gin Web Framework")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Equal(t, "Gin Web Framework", w.Body.String())
|
||||
assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
|
||||
w3 := performRequest(router, "HEAD", "/using_static/"+filename)
|
||||
w4 := performRequest(router, "HEAD", "/result")
|
||||
|
||||
assert.Equal(t, w3, w4)
|
||||
assert.Equal(t, w3.Code, 200)
|
||||
assert.Equal(t, 200, w3.Code)
|
||||
}
|
||||
|
||||
// TestHandleStaticDir - ensure the root/sub dir handles properly
|
||||
|
@ -283,9 +283,9 @@ func TestRouteStaticListingDir(t *testing.T) {
|
|||
|
||||
w := performRequest(router, "GET", "/")
|
||||
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "gin.go")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8")
|
||||
assert.Equal(t, "text/html; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// TestHandleHeadToDir - ensure the root/sub dir handles properly
|
||||
|
@ -295,7 +295,7 @@ func TestRouteStaticNoListing(t *testing.T) {
|
|||
|
||||
w := performRequest(router, "GET", "/")
|
||||
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
assert.NotContains(t, w.Body.String(), "gin.go")
|
||||
}
|
||||
|
||||
|
@ -310,12 +310,12 @@ func TestRouterMiddlewareAndStatic(t *testing.T) {
|
|||
|
||||
w := performRequest(router, "GET", "/gin.go")
|
||||
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "package gin")
|
||||
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")
|
||||
assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.Get("Content-Type"))
|
||||
assert.NotEqual(t, w.HeaderMap.Get("Last-Modified"), "Mon, 02 Jan 2006 15:04:05 MST")
|
||||
assert.Equal(t, w.HeaderMap.Get("Expires"), "Mon, 02 Jan 2006 15:04:05 MST")
|
||||
assert.Equal(t, w.HeaderMap.Get("x-GIN"), "Gin Framework")
|
||||
assert.Equal(t, "Mon, 02 Jan 2006 15:04:05 MST", w.HeaderMap.Get("Expires"))
|
||||
assert.Equal(t, "Gin Framework", w.HeaderMap.Get("x-GIN"))
|
||||
}
|
||||
|
||||
func TestRouteNotAllowedEnabled(t *testing.T) {
|
||||
|
@ -323,14 +323,14 @@ func TestRouteNotAllowedEnabled(t *testing.T) {
|
|||
router.HandleMethodNotAllowed = true
|
||||
router.POST("/path", func(c *Context) {})
|
||||
w := performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Code, http.StatusMethodNotAllowed)
|
||||
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
||||
|
||||
router.NoMethod(func(c *Context) {
|
||||
c.String(http.StatusTeapot, "responseText")
|
||||
})
|
||||
w = performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Body.String(), "responseText")
|
||||
assert.Equal(t, w.Code, http.StatusTeapot)
|
||||
assert.Equal(t, "responseText", w.Body.String())
|
||||
assert.Equal(t, http.StatusTeapot, w.Code)
|
||||
}
|
||||
|
||||
func TestRouteNotAllowedDisabled(t *testing.T) {
|
||||
|
@ -338,14 +338,14 @@ func TestRouteNotAllowedDisabled(t *testing.T) {
|
|||
router.HandleMethodNotAllowed = false
|
||||
router.POST("/path", func(c *Context) {})
|
||||
w := performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
|
||||
router.NoMethod(func(c *Context) {
|
||||
c.String(http.StatusTeapot, "responseText")
|
||||
})
|
||||
w = performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Body.String(), "404 page not found")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, "404 page not found", w.Body.String())
|
||||
assert.Equal(t, 404, w.Code)
|
||||
}
|
||||
|
||||
func TestRouterNotFound(t *testing.T) {
|
||||
|
@ -372,9 +372,9 @@ func TestRouterNotFound(t *testing.T) {
|
|||
}
|
||||
for _, tr := range testRoutes {
|
||||
w := performRequest(router, "GET", tr.route)
|
||||
assert.Equal(t, w.Code, tr.code)
|
||||
assert.Equal(t, tr.code, w.Code)
|
||||
if w.Code != 404 {
|
||||
assert.Equal(t, fmt.Sprint(w.Header().Get("Location")), tr.location)
|
||||
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,20 +385,20 @@ func TestRouterNotFound(t *testing.T) {
|
|||
notFound = true
|
||||
})
|
||||
w := performRequest(router, "GET", "/nope")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
assert.True(t, notFound)
|
||||
|
||||
// Test other method than GET (want 307 instead of 301)
|
||||
router.PATCH("/path", func(c *Context) {})
|
||||
w = performRequest(router, "PATCH", "/path/")
|
||||
assert.Equal(t, w.Code, 307)
|
||||
assert.Equal(t, fmt.Sprint(w.Header()), "map[Location:[/path]]")
|
||||
assert.Equal(t, 307, w.Code)
|
||||
assert.Equal(t, "map[Location:[/path]]", fmt.Sprint(w.Header()))
|
||||
|
||||
// Test special case where no node for the prefix "/" exists
|
||||
router = New()
|
||||
router.GET("/a", func(c *Context) {})
|
||||
w = performRequest(router, "GET", "/")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
assert.Equal(t, 404, w.Code)
|
||||
}
|
||||
|
||||
func TestRouteRawPath(t *testing.T) {
|
||||
|
@ -409,15 +409,15 @@ func TestRouteRawPath(t *testing.T) {
|
|||
name := c.Params.ByName("name")
|
||||
num := c.Params.ByName("num")
|
||||
|
||||
assert.Equal(t, c.Param("name"), name)
|
||||
assert.Equal(t, c.Param("num"), num)
|
||||
assert.Equal(t, name, c.Param("name"))
|
||||
assert.Equal(t, num, c.Param("num"))
|
||||
|
||||
assert.Equal(t, "Some/Other/Project", name)
|
||||
assert.Equal(t, "222", num)
|
||||
})
|
||||
|
||||
w := performRequest(route, "POST", "/project/Some%2FOther%2FProject/build/222")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
}
|
||||
|
||||
func TestRouteRawPathNoUnescape(t *testing.T) {
|
||||
|
@ -429,15 +429,15 @@ func TestRouteRawPathNoUnescape(t *testing.T) {
|
|||
name := c.Params.ByName("name")
|
||||
num := c.Params.ByName("num")
|
||||
|
||||
assert.Equal(t, c.Param("name"), name)
|
||||
assert.Equal(t, c.Param("num"), num)
|
||||
assert.Equal(t, name, c.Param("name"))
|
||||
assert.Equal(t, num, c.Param("num"))
|
||||
|
||||
assert.Equal(t, "Some%2FOther%2FProject", name)
|
||||
assert.Equal(t, "333", num)
|
||||
})
|
||||
|
||||
w := performRequest(route, "POST", "/project/Some%2FOther%2FProject/build/333")
|
||||
assert.Equal(t, w.Code, 200)
|
||||
assert.Equal(t, 200, w.Code)
|
||||
}
|
||||
|
||||
func TestRouteServeErrorWithWriteHeader(t *testing.T) {
|
||||
|
|
|
@ -21,8 +21,8 @@ type testStruct struct {
|
|||
}
|
||||
|
||||
func (t *testStruct) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
assert.Equal(t.T, req.Method, "POST")
|
||||
assert.Equal(t.T, req.URL.Path, "/path")
|
||||
assert.Equal(t.T, "POST", req.Method)
|
||||
assert.Equal(t.T, "/path", req.URL.Path)
|
||||
w.WriteHeader(500)
|
||||
fmt.Fprint(w, "hello")
|
||||
}
|
||||
|
@ -31,50 +31,50 @@ func TestWrap(t *testing.T) {
|
|||
router := New()
|
||||
router.POST("/path", WrapH(&testStruct{t}))
|
||||
router.GET("/path2", WrapF(func(w http.ResponseWriter, req *http.Request) {
|
||||
assert.Equal(t, req.Method, "GET")
|
||||
assert.Equal(t, req.URL.Path, "/path2")
|
||||
assert.Equal(t, "GET", req.Method)
|
||||
assert.Equal(t, "/path2", req.URL.Path)
|
||||
w.WriteHeader(400)
|
||||
fmt.Fprint(w, "hola!")
|
||||
}))
|
||||
|
||||
w := performRequest(router, "POST", "/path")
|
||||
assert.Equal(t, w.Code, 500)
|
||||
assert.Equal(t, w.Body.String(), "hello")
|
||||
assert.Equal(t, 500, w.Code)
|
||||
assert.Equal(t, "hello", w.Body.String())
|
||||
|
||||
w = performRequest(router, "GET", "/path2")
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.Equal(t, w.Body.String(), "hola!")
|
||||
assert.Equal(t, 400, w.Code)
|
||||
assert.Equal(t, "hola!", w.Body.String())
|
||||
}
|
||||
|
||||
func TestLastChar(t *testing.T) {
|
||||
assert.Equal(t, lastChar("hola"), uint8('a'))
|
||||
assert.Equal(t, lastChar("adios"), uint8('s'))
|
||||
assert.Equal(t, uint8('a'), lastChar("hola"))
|
||||
assert.Equal(t, uint8('s'), lastChar("adios"))
|
||||
assert.Panics(t, func() { lastChar("") })
|
||||
}
|
||||
|
||||
func TestParseAccept(t *testing.T) {
|
||||
parts := parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
|
||||
assert.Len(t, parts, 4)
|
||||
assert.Equal(t, parts[0], "text/html")
|
||||
assert.Equal(t, parts[1], "application/xhtml+xml")
|
||||
assert.Equal(t, parts[2], "application/xml")
|
||||
assert.Equal(t, parts[3], "*/*")
|
||||
assert.Equal(t, "text/html", parts[0])
|
||||
assert.Equal(t, "application/xhtml+xml", parts[1])
|
||||
assert.Equal(t, "application/xml", parts[2])
|
||||
assert.Equal(t, "*/*", parts[3])
|
||||
}
|
||||
|
||||
func TestChooseData(t *testing.T) {
|
||||
A := "a"
|
||||
B := "b"
|
||||
assert.Equal(t, chooseData(A, B), A)
|
||||
assert.Equal(t, chooseData(nil, B), B)
|
||||
assert.Equal(t, A, chooseData(A, B))
|
||||
assert.Equal(t, B, chooseData(nil, B))
|
||||
assert.Panics(t, func() { chooseData(nil, nil) })
|
||||
}
|
||||
|
||||
func TestFilterFlags(t *testing.T) {
|
||||
result := filterFlags("text/html ")
|
||||
assert.Equal(t, result, "text/html")
|
||||
assert.Equal(t, "text/html", result)
|
||||
|
||||
result = filterFlags("text/html;")
|
||||
assert.Equal(t, result, "text/html")
|
||||
assert.Equal(t, "text/html", result)
|
||||
}
|
||||
|
||||
func TestFunctionName(t *testing.T) {
|
||||
|
@ -86,16 +86,16 @@ func somefunction() {
|
|||
}
|
||||
|
||||
func TestJoinPaths(t *testing.T) {
|
||||
assert.Equal(t, joinPaths("", ""), "")
|
||||
assert.Equal(t, joinPaths("", "/"), "/")
|
||||
assert.Equal(t, joinPaths("/a", ""), "/a")
|
||||
assert.Equal(t, joinPaths("/a/", ""), "/a/")
|
||||
assert.Equal(t, joinPaths("/a/", "/"), "/a/")
|
||||
assert.Equal(t, joinPaths("/a", "/"), "/a/")
|
||||
assert.Equal(t, joinPaths("/a", "/hola"), "/a/hola")
|
||||
assert.Equal(t, joinPaths("/a/", "/hola"), "/a/hola")
|
||||
assert.Equal(t, joinPaths("/a/", "/hola/"), "/a/hola/")
|
||||
assert.Equal(t, joinPaths("/a/", "/hola//"), "/a/hola/")
|
||||
assert.Equal(t, "", joinPaths("", ""))
|
||||
assert.Equal(t, "/", joinPaths("", "/"))
|
||||
assert.Equal(t, "/a", joinPaths("/a", ""))
|
||||
assert.Equal(t, "/a/", joinPaths("/a/", ""))
|
||||
assert.Equal(t, "/a/", joinPaths("/a/", "/"))
|
||||
assert.Equal(t, "/a/", joinPaths("/a", "/"))
|
||||
assert.Equal(t, "/a/hola", joinPaths("/a", "/hola"))
|
||||
assert.Equal(t, "/a/hola", joinPaths("/a/", "/hola"))
|
||||
assert.Equal(t, "/a/hola/", joinPaths("/a/", "/hola/"))
|
||||
assert.Equal(t, "/a/hola/", joinPaths("/a/", "/hola//"))
|
||||
}
|
||||
|
||||
type bindTestStruct struct {
|
||||
|
@ -113,8 +113,8 @@ func TestBindMiddleware(t *testing.T) {
|
|||
})
|
||||
performRequest(router, "GET", "/?foo=hola&bar=10")
|
||||
assert.True(t, called)
|
||||
assert.Equal(t, value.Foo, "hola")
|
||||
assert.Equal(t, value.Bar, 10)
|
||||
assert.Equal(t, "hola", value.Foo)
|
||||
assert.Equal(t, 10, value.Bar)
|
||||
|
||||
called = false
|
||||
performRequest(router, "GET", "/?foo=hola&bar=1")
|
||||
|
|
Loading…
Reference in New Issue