aboutsummaryrefslogtreecommitdiffhomepage
path: root/http/client/response_test.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-04-28 10:51:07 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-04-28 10:51:07 -0700
commit1eba1730d1af50ed545f4fde78b22d6fb62ca11e (patch)
tree61f99282f66529b42625a8f335593bdcb461459c /http/client/response_test.go
parent04adf5fdf53951f270923c41171a52575db53e46 (diff)
Move HTTP client to its own package
Diffstat (limited to 'http/client/response_test.go')
-rw-r--r--http/client/response_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/http/client/response_test.go b/http/client/response_test.go
new file mode 100644
index 0000000..f3402a8
--- /dev/null
+++ b/http/client/response_test.go
@@ -0,0 +1,56 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package client
+
+import "testing"
+
+func TestHasServerFailureWith200Status(t *testing.T) {
+ r := &Response{StatusCode: 200}
+ if r.HasServerFailure() {
+ t.Error("200 is not a failure")
+ }
+}
+
+func TestHasServerFailureWith404Status(t *testing.T) {
+ r := &Response{StatusCode: 404}
+ if !r.HasServerFailure() {
+ t.Error("404 is a failure")
+ }
+}
+
+func TestHasServerFailureWith500Status(t *testing.T) {
+ r := &Response{StatusCode: 500}
+ if !r.HasServerFailure() {
+ t.Error("500 is a failure")
+ }
+}
+
+func TestIsModifiedWith304Status(t *testing.T) {
+ r := &Response{StatusCode: 304}
+ if r.IsModified("etag", "lastModified") {
+ t.Error("The resource should not be considered modified")
+ }
+}
+
+func TestIsModifiedWithIdenticalEtag(t *testing.T) {
+ r := &Response{StatusCode: 200, ETag: "etag"}
+ if r.IsModified("etag", "lastModified") {
+ t.Error("The resource should not be considered modified")
+ }
+}
+
+func TestIsModifiedWithIdenticalLastModified(t *testing.T) {
+ r := &Response{StatusCode: 200, LastModified: "lastModified"}
+ if r.IsModified("etag", "lastModified") {
+ t.Error("The resource should not be considered modified")
+ }
+}
+
+func TestIsModifiedWithDifferentHeaders(t *testing.T) {
+ r := &Response{StatusCode: 200, ETag: "some etag", LastModified: "some date"}
+ if !r.IsModified("etag", "lastModified") {
+ t.Error("The resource should be considered modified")
+ }
+}