Skip to content

Commit a671a21

Browse files
committed
Add unit test of :method when redirecting
1 parent 34a7646 commit a671a21

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

test/aleph/http_test.clj

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,32 @@
328328
(is (= characters body'))))))
329329

330330
(deftest test-redirect
331-
(with-both-handlers basic-handler
332-
(is (= "ok"
333-
(-> @(http-get (str "http://localhost:" port "/redirect?count=10"))
334-
:body
335-
bs/to-string)))
336-
(is (= "redirected!"
337-
(-> @(http-get (str "http://localhost:" port "/redirect?count=25"))
338-
:body
339-
bs/to-string)))
340-
(is (= "ok"
341-
(-> @(http-get (str "http://localhost:" port "/redirect?count=25")
342-
{:max-redirects 30})
343-
:body
344-
bs/to-string)))))
331+
(testing "basic redirecting"
332+
(with-both-handlers basic-handler
333+
(is (= "ok"
334+
(-> @(http-get (str "http://localhost:" port "/redirect?count=10"))
335+
:body
336+
bs/to-string)))
337+
(is (= "redirected!"
338+
(-> @(http-get (str "http://localhost:" port "/redirect?count=25"))
339+
:body
340+
bs/to-string)))
341+
(is (= "ok"
342+
(-> @(http-get (str "http://localhost:" port "/redirect?count=25")
343+
{:max-redirects 30})
344+
:body
345+
bs/to-string)))))
346+
347+
(testing "works with :method as well as :request-method"
348+
(with-handler
349+
(fn [{:keys [uri]}]
350+
(case uri
351+
"/200" {:status 200}
352+
"/301" {:status 301
353+
:headers {"Location" "/200"}}))
354+
(is (= 200 (:status @(http/request {:method :get
355+
:url (str "http://localhost:" port "/301")
356+
:follow-redirects? true})))))))
345357

346358
(deftest test-middleware
347359
(with-both-handlers basic-handler

0 commit comments

Comments
 (0)