From 8e37eb84984714af6cea105d1885798b70025444 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Fri, 2 Oct 2015 12:37:51 +0200 Subject: [PATCH] Fix tests for GetCookie() and SetCookie() --- context.go | 6 +++--- context_test.go | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/context.go b/context.go index 4bf7986..a636f7a 100644 --- a/context.go +++ b/context.go @@ -349,13 +349,13 @@ func (c *Context) SetCookie( c.Writer.Header().Add("Set-Cookie", cookie.String()) } -func (c *Context) GetCookie(name string) string { +func (c *Context) GetCookie(name string) (string, error) { cookie, err := c.Request.Cookie(name) if err != nil { - return "" + return "", err } val, _ := url.QueryUnescape(cookie.Value) - return val + return val, nil } func (c *Context) Render(code int, r render.Render) { diff --git a/context_test.go b/context_test.go index 18e5460..c6bb591 100644 --- a/context_test.go +++ b/context_test.go @@ -248,20 +248,18 @@ func TestContextPostFormMultipart(t *testing.T) { } func TestContextSetCookie(t *testing.T) { - c, w, _ := createTestContext() + c, _, _ := createTestContext() c.SetCookie("user", "gin", 1, "/", "localhost", true, true) - c.SetCookie("user", "gin", int32(1), "/", "localhost", 1) - c.SetCookie("user", "gin", int64(1)) - c.Request, _ = http.NewRequest("GET", "/set", nil) - assert.Equal(t, c.GetCookie("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 TestContextGetCookie(t *testing.T) { - c, w, _ := createTestContext() + c, _, _ := createTestContext() c.Request, _ = http.NewRequest("GET", "/get", nil) c.Request.Header.Set("Cookie", "user=gin") - assert.Equal(t, c.GetCookie("Cookie"), "gin") + cookie, _ := c.GetCookie("user") + assert.Equal(t, cookie, "gin") } // Tests that the response is serialized as JSON