cookie_test.go 876 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package request // import "miniflux.app/http/request"
  5. import (
  6. "net/http"
  7. "testing"
  8. )
  9. func TestGetCookieValue(t *testing.T) {
  10. r, _ := http.NewRequest("GET", "http://example.org", nil)
  11. r.AddCookie(&http.Cookie{Value: "cookie_value", Name: "my_cookie"})
  12. result := CookieValue(r, "my_cookie")
  13. expected := "cookie_value"
  14. if result != expected {
  15. t.Errorf(`Unexpected cookie value, got %q instead of %q`, result, expected)
  16. }
  17. }
  18. func TestGetCookieValueWhenUnset(t *testing.T) {
  19. r, _ := http.NewRequest("GET", "http://example.org", nil)
  20. result := CookieValue(r, "my_cookie")
  21. expected := ""
  22. if result != expected {
  23. t.Errorf(`Unexpected cookie value, got %q instead of %q`, result, expected)
  24. }
  25. }