aboutsummaryrefslogtreecommitdiffhomepage
path: root/reader
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-11-20 17:25:45 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-11-20 17:25:45 -0800
commitc5cd38de832fffb20cbf97a60babe8cbc42fde1e (patch)
tree0a516cc4629a10f636d232d645c954b361243974 /reader
parentaecda64030ef1231244b8b2ab8be0174f6bfd992 (diff)
Add unit test for HTTP client response functions
Diffstat (limited to 'reader')
-rw-r--r--reader/http/response.go6
-rw-r--r--reader/http/response_test.go56
2 files changed, 61 insertions, 1 deletions
diff --git a/reader/http/response.go b/reader/http/response.go
index b2dfb54..f79b45b 100644
--- a/reader/http/response.go
+++ b/reader/http/response.go
@@ -28,7 +28,11 @@ func (r *Response) IsModified(etag, lastModified string) bool {
return false
}
- if r.ETag != "" && r.LastModified != "" && (r.ETag == etag || r.LastModified == lastModified) {
+ if r.ETag != "" && r.ETag == etag {
+ return false
+ }
+
+ if r.LastModified != "" && r.LastModified == lastModified {
return false
}
diff --git a/reader/http/response_test.go b/reader/http/response_test.go
new file mode 100644
index 0000000..c5f6a1c
--- /dev/null
+++ b/reader/http/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 http
+
+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")
+ }
+}