Something went wrong. Try again.
Lightweight and easily self-hostable Git forge.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960package lib
import ( "net/http" "net/http/httptest" "testing" "time")
func TestSetCookie(t *testing.T) { rec := httptest.NewRecorder() SetCookie(rec, "session", "abc123")
cookies := rec.Result().Cookies() if len(cookies) != 1 { t.Fatalf("SetCookie set %d cookies, want 1", len(cookies)) } c := cookies[0]
if c.Name != "session" || c.Value != "abc123" { t.Errorf("cookie = %s=%s, want session=abc123", c.Name, c.Value) } if !c.HttpOnly { t.Error("cookie is not HttpOnly") } if !c.Secure { t.Error("cookie is not Secure") } if c.SameSite != http.SameSiteLaxMode { t.Errorf("SameSite = %v, want SameSiteLaxMode", c.SameSite) } if c.Path != "/" { t.Errorf("Path = %q, want /", c.Path) } if !c.Expires.After(time.Now().Add(time.Hour * 24 * 6)) { t.Errorf("Expires = %v, want ~7 days out", c.Expires) }}
func TestDeleteCookie(t *testing.T) { rec := httptest.NewRecorder() DeleteCookie(rec, "session")
cookies := rec.Result().Cookies() if len(cookies) != 1 { t.Fatalf("DeleteCookie set %d cookies, want 1", len(cookies)) } c := cookies[0]
if c.Name != "session" || c.Value != "" { t.Errorf("cookie = %s=%q, want session=", c.Name, c.Value) } if c.MaxAge != -1 { t.Errorf("MaxAge = %d, want -1", c.MaxAge) } if !c.Expires.Before(time.Now()) { t.Error("Expires is not in the past") }}