Skip to content

Commit

Permalink
Tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrGlad committed Mar 5, 2013
1 parent 50b3611 commit dc37f6d
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions ring-core/test/ring/middleware/test/not_modified.clj
Expand Up @@ -21,36 +21,29 @@
{:headers {"if-modified-since" modified-date}})

(deftest test-wrap-not-modified
(testing "etags"
(let [h (wrap-not-modified (handler-etag "\"12345\""))]
(is (= 304 (:status (h (etag-request "\"12345\"")))))
(is (= 200 (:status (h (etag-request "\"abcde\"")))))))
(testing "last-modified"
(let [baseline "Sun, 23 Sep 2012 10:00:00 GMT"
h (wrap-not-modified (handler-modified baseline))]
(is (= 304 (:status (h (modified-request baseline)))))
(is (= 304 (:status (h (modified-request "Sun, 23 Sep 2012 11:00:00 GMT")))))
(is (= 200 (:status (h (modified-request "Sun, 23 Sep 2012 09:52:50 GMT")))))))
(testing "no modified info"
(let [h (wrap-not-modified (constantly {:status 200 :headers {} :body ""}))]
(is (= 200 (:status (h (etag-request "\"12345\"")))))
(is (= 200 (:status (h (modified-request "Sun, 23 Sep 2012 10:00:00 GMT"))))))))

(deftest not-modified-response-etag-match
(let [req {:headers {"if-none-match" "match"}}
h-resp {:status 200 :headers {"etag" "match"} :body ""}]
(is (= 304 (:status (not-modified-response h-resp req))))))

(deftest not-modified-response-etag-no-match
(let [req {:headers {"if-none-match" "match"}}
h-resp {:status 200 :headers {"etag" "no-match"} :body ""}]
(is (= 200 (:status (not-modified-response h-resp req))))))

(deftest not-modified-response
(let [req #(hash-map :headers {"if-modified-since" %})
last-modified "Sun, 23 Sep 2012 11:00:00 GMT"
h-resp {:status 200 :headers {"last-modified" last-modified} :body ""}]
(is (= 304 (:status (not-modified-response h-resp (req baseline)))))
(is (= 304 (:status (not-modified-response h-resp (req "Sun, 23 Sep 2012 11:52:50 GMT")))))
(is (= 200 (:status (not-modified-response h-resp (req "Sun, 23 Sep 2012 10:00:50 GMT")))))))

(with-redefs [ring.middleware.not-modified/not-modified-response #(vector %1 %2)]
(let [req (modified-request "Sun, 23 Sep 2012 11:00:00 GMT")
handler (handler-modified "Jan, 23 Sep 2012 11:00:00 GMT")]
(is (= [(handler req) req]
((wrap-not-modified handler) req))))))

(deftest test-not-modified-response
(testing "etag match"
(let [request-etag "match"
req {:headers {"if-none-match" request-etag}}
handler-resp #(hash-map :status 200 :headers {"etag" %} :body "")]
(is (= 304 (:status (not-modified-response (handler-resp request-etag) req))))
(is (= 200 (:status (not-modified-response (handler-resp "laskdhfskljahdflksjdhf") req))))))

(testing "not modified"
(let [req #(hash-map :headers {"if-modified-since" %})
last-modified "Sun, 23 Sep 2012 11:00:00 GMT"
h-resp {:status 200 :headers {"last-modified" last-modified} :body ""}]
(is (= 304 (:status (not-modified-response h-resp (req last-modified)))))
(is (= 304 (:status (not-modified-response h-resp (req "Sun, 23 Sep 2012 11:52:50 GMT")))))
(is (= 200 (:status (not-modified-response h-resp (req "Sun, 23 Sep 2012 10:00:50 GMT")))))))

(testing "no modification info"
(let [response {:status 200 :headers {} :body ""}]
(is (= 200 (:status (not-modified-response response (etag-request "\"12345\"")))))
(is (= 200 (:status (not-modified-response response (modified-request "Sun, 23 Sep 2012 10:00:00 GMT"))))))))

0 comments on commit dc37f6d

Please sign in to comment.