cookie_test.go 841 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package request // import "miniflux.app/v2/internal/http/request"
  4. import (
  5. "net/http"
  6. "testing"
  7. )
  8. func TestGetCookieValue(t *testing.T) {
  9. r, _ := http.NewRequest("GET", "http://example.org", nil)
  10. r.AddCookie(&http.Cookie{Value: "cookie_value", Name: "my_cookie"})
  11. result := CookieValue(r, "my_cookie")
  12. expected := "cookie_value"
  13. if result != expected {
  14. t.Errorf(`Unexpected cookie value, got %q instead of %q`, result, expected)
  15. }
  16. }
  17. func TestGetCookieValueWhenUnset(t *testing.T) {
  18. r, _ := http.NewRequest("GET", "http://example.org", nil)
  19. result := CookieValue(r, "my_cookie")
  20. expected := ""
  21. if result != expected {
  22. t.Errorf(`Unexpected cookie value, got %q instead of %q`, result, expected)
  23. }
  24. }