Add tests for getSessionCookie
This commit is contained in:
parent
f7b8018c62
commit
e06dda9a31
30
session_test.go
Normal file
30
session_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetSessionCookieMissingCookie(t *testing.T) {
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
sessionKey, err := getSessionCookie(w, r)
|
||||
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if sessionKey == "" {
|
||||
t.Errorf("Session key is empty")
|
||||
}
|
||||
|
||||
cookies := w.Result().Cookies()
|
||||
for _, c := range cookies {
|
||||
if c.Name == "session" {
|
||||
if c.Value != sessionKey {
|
||||
t.Errorf("Wrong sessionKey %q != %q", c.Value, sessionKey)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user