fixed tests.

This commit is contained in:
anio 2018-10-29 09:11:32 +00:00
parent 1133e83701
commit 211510c502
2 changed files with 6 additions and 6 deletions

View File

@ -686,7 +686,7 @@ func (c *Context) GetRawData() ([]byte, error) {
// SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
// The provided cookie must have a valid Name. Invalid cookies may be
// silently dropped.
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool, sameSite string) {
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, sameSite string, secure, httpOnly bool) {
if path == "" {
path = "/"
}
@ -696,9 +696,9 @@ func (c *Context) SetCookie(name, value string, maxAge int, path, domain string,
MaxAge: maxAge,
Path: path,
Domain: domain,
SameSite: sameSite,
Secure: secure,
HttpOnly: httpOnly,
SameSite: sameSite,
})
}

View File

@ -579,14 +579,14 @@ 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, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; SameSite=Lax; Secure", c.Writer.Header().Get("Set-Cookie"))
c.SetCookie("user", "gin", 1, "/", "localhost", "Lax", true, true)
assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; SameSite=Lax; 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, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; SameSite=Lax; Secure", c.Writer.Header().Get("Set-Cookie"))
c.SetCookie("user", "gin", 1, "", "localhost", "Lax", true, true)
assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; SameSite=Lax; HttpOnly; Secure", c.Writer.Header().Get("Set-Cookie"))
}
func TestContextGetCookie(t *testing.T) {