mirror of https://github.com/gin-gonic/gin.git
Improve cookie tests code coverage (#918)
This commit is contained in:
parent
d4a53101c3
commit
214a746b1d
|
@ -384,12 +384,21 @@ func TestContextSetCookie(t *testing.T) {
|
||||||
assert.Equal(t, c.Writer.Header().Get("Set-Cookie"), "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure")
|
assert.Equal(t, c.Writer.Header().Get("Set-Cookie"), "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextGetCookie(t *testing.T) {
|
func TestContextGetCookie(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
c.Request, _ = http.NewRequest("GET", "/get", nil)
|
c.Request, _ = http.NewRequest("GET", "/get", nil)
|
||||||
c.Request.Header.Set("Cookie", "user=gin")
|
c.Request.Header.Set("Cookie", "user=gin")
|
||||||
cookie, _ := c.Cookie("user")
|
cookie, _ := c.Cookie("user")
|
||||||
assert.Equal(t, cookie, "gin")
|
assert.Equal(t, cookie, "gin")
|
||||||
|
|
||||||
|
_, err := c.Cookie("nokey")
|
||||||
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextBodyAllowedForStatus(t *testing.T) {
|
func TestContextBodyAllowedForStatus(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue