fetch the right cookie

This commit is contained in:
Peter Stuifzand 2018-10-01 22:50:20 +02:00
parent e06dda9a31
commit 96103e4d7c

View File

@ -28,3 +28,21 @@ func TestGetSessionCookieMissingCookie(t *testing.T) {
}
}
}
func TestGetSessionCookieCookieSet(t *testing.T) {
mySessionKey := "12341234"
r, _ := http.NewRequest("GET", "/", nil)
cookie := &http.Cookie{Name: "session", Value: mySessionKey}
r.AddCookie(cookie)
w := httptest.NewRecorder()
sessionKey, err := getSessionCookie(w, r)
if err != nil {
t.Errorf("err != nil in getSessionCookie")
}
if mySessionKey != sessionKey {
t.Errorf("getSessionKey didn't fetch sessionKey from \"session\" cookie")
}
}