Skip to content

Commit 7d62d70

Browse files
committed
remove 'http://localhost:18080' from the tests in favor of something
more easily changeable
1 parent 8e8b2ed commit 7d62d70

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

test/clj_http/test/core.clj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
(defonce server
6262
(future (ring/run-jetty handler {:port 18080}))))
6363

64+
(defn localhost [path]
65+
(str "http://localhost:18080" path))
66+
6467
(def base-req
6568
{:scheme :http
6669
:server-name "localhost"
@@ -173,7 +176,7 @@
173176
:save-request? true})]
174177
(is (= 200 (:status resp)))
175178
(is (= {:scheme :http
176-
:http-url "http://localhost:18080/post"
179+
:http-url (localhost "/post")
177180
:request-method :post
178181
:save-request? true
179182
:uri "/post"
@@ -213,16 +216,16 @@
213216

214217
(deftest ^{:integration true} throw-on-too-many-redirects
215218
(run-server)
216-
(let [resp (client/get "http://localhost:18080/redirect"
219+
(let [resp (client/get (localhost "/redirect")
217220
{:max-redirects 2 :throw-exceptions false})]
218221
(is (= 302 (:status resp)))
219222
(is (= (apply vector (repeat 3 "http://localhost:18080/redirect"))
220223
(:trace-redirects resp))))
221224
(is (thrown-with-msg? Exception #"Too many redirects: 3"
222-
(client/get "http://localhost:18080/redirect"
225+
(client/get (localhost "/redirect")
223226
{:max-redirects 2 :throw-exceptions true})))
224227
(is (thrown-with-msg? Exception #"Too many redirects: 21"
225-
(client/get "http://localhost:18080/redirect"
228+
(client/get (localhost "/redirect")
226229
{:throw-exceptions true}))))
227230

228231
(deftest ^{:integration true} get-with-body
@@ -239,17 +242,17 @@
239242

240243
(deftest ^{:integration true} t-clojure-output-coercion
241244
(run-server)
242-
(let [resp (client/get "http://localhost:18080/clojure" {:as :clojure})]
245+
(let [resp (client/get (localhost "/clojure") {:as :clojure})]
243246
(is (= 200 (:status resp)))
244247
(is (= {:foo "bar" :baz 7M :eggplant {:quux #{1 2 3}}} (:body resp))))
245-
(let [resp (client/get "http://localhost:18080/clojure" {:as :auto})]
248+
(let [resp (client/get (localhost "/clojure") {:as :auto})]
246249
(is (= 200 (:status resp)))
247250
(is (= {:foo "bar" :baz 7M :eggplant {:quux #{1 2 3}}} (:body resp)))))
248251

249252
(deftest ^{:integration true} t-json-output-coercion
250253
(run-server)
251-
(let [resp (client/get "http://localhost:18080/json" {:as :json})
252-
bad-resp (client/get "http://localhost:18080/json-bad"
254+
(let [resp (client/get (localhost "/json") {:as :json})
255+
bad-resp (client/get (localhost "/json-bad")
253256
{:throw-exceptions false :as :json})]
254257
(is (= 200 (:status resp)))
255258
(is (= {:foo "bar"} (:body resp)))
@@ -278,10 +281,10 @@
278281
;; super-basic test for methods that aren't used that often
279282
(deftest ^{:integration true} t-copy-options-move
280283
(run-server)
281-
(let [resp1 (client/options "http://localhost:18080/options")
282-
resp2 (client/move "http://localhost:18080/move")
283-
resp3 (client/copy "http://localhost:18080/copy")
284-
resp4 (client/patch "http://localhost:18080/patch")]
284+
(let [resp1 (client/options (localhost "/options"))
285+
resp2 (client/move (localhost "/move"))
286+
resp3 (client/copy (localhost "/copy"))
287+
resp4 (client/patch (localhost "/patch"))]
285288
(is (= #{200} (set (map :status [resp1 resp2 resp3 resp4]))))
286289
(is (= "options" (:body resp1)))
287290
(is (= "move" (:body resp2)))
@@ -291,7 +294,7 @@
291294
(deftest ^{:integration true} t-json-encoded-form-params
292295
(run-server)
293296
(let [params {:param1 "value1" :param2 "value2"}
294-
resp (client/post "http://localhost:18080/post" {:content-type :json
295-
:form-params params})]
297+
resp (client/post (localhost "/post") {:content-type :json
298+
:form-params params})]
296299
(is (= 200 (:status resp)))
297300
(is (= (json/encode params) (:body resp)))))

0 commit comments

Comments
 (0)