response_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 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 http
  5. import "testing"
  6. func TestHasServerFailureWith200Status(t *testing.T) {
  7. r := &Response{StatusCode: 200}
  8. if r.HasServerFailure() {
  9. t.Error("200 is not a failure")
  10. }
  11. }
  12. func TestHasServerFailureWith404Status(t *testing.T) {
  13. r := &Response{StatusCode: 404}
  14. if !r.HasServerFailure() {
  15. t.Error("404 is a failure")
  16. }
  17. }
  18. func TestHasServerFailureWith500Status(t *testing.T) {
  19. r := &Response{StatusCode: 500}
  20. if !r.HasServerFailure() {
  21. t.Error("500 is a failure")
  22. }
  23. }
  24. func TestIsModifiedWith304Status(t *testing.T) {
  25. r := &Response{StatusCode: 304}
  26. if r.IsModified("etag", "lastModified") {
  27. t.Error("The resource should not be considered modified")
  28. }
  29. }
  30. func TestIsModifiedWithIdenticalEtag(t *testing.T) {
  31. r := &Response{StatusCode: 200, ETag: "etag"}
  32. if r.IsModified("etag", "lastModified") {
  33. t.Error("The resource should not be considered modified")
  34. }
  35. }
  36. func TestIsModifiedWithIdenticalLastModified(t *testing.T) {
  37. r := &Response{StatusCode: 200, LastModified: "lastModified"}
  38. if r.IsModified("etag", "lastModified") {
  39. t.Error("The resource should not be considered modified")
  40. }
  41. }
  42. func TestIsModifiedWithDifferentHeaders(t *testing.T) {
  43. r := &Response{StatusCode: 200, ETag: "some etag", LastModified: "some date"}
  44. if !r.IsModified("etag", "lastModified") {
  45. t.Error("The resource should be considered modified")
  46. }
  47. }