Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit a5fc650

Browse files
committed
Add more tests for Request building
1 parent 276dd35 commit a5fc650

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/clj_docker_client/requests.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@
101101
req-body (cond
102102
(nil? body)
103103
(RequestBody/create nil "")
104+
104105
(map? body)
105106
(RequestBody/create (json/write-value-as-string body)
106107
(MediaType/get "application/json; charset=utf-8"))
108+
107109
(instance? InputStream body)
108110
(stream->req-body body))
109111
req (case method

test/clj_docker_client/requests_test.clj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,27 @@
9595
(testing "build a post request with a map body"
9696
(let [req (build-request {:method :post
9797
:url "http://aurl"
98-
:body {:key "value"}})
99-
mime-type (-> req .body .contentType str)]
100-
(is (= "application/json; charset=utf-8" mime-type))))
98+
:body {:key "value"}})]
99+
(is (= "application/json; charset=utf-8"
100+
(-> req .body .contentType str)))))
101101

102102
(testing "build a post request with a stream body"
103103
(let [req (build-request {:method :post
104104
:url "http://aurl"
105105
:body (-> "README.md"
106106
io/file
107-
io/input-stream)})
108-
mime-type (-> req .body .contentType str)]
109-
(is (= "application/octet-stream" mime-type)))))
107+
io/input-stream)})]
108+
(is (= "application/octet-stream"
109+
(-> req .body .contentType str)))))
110+
111+
(testing "build a request with query and header params"
112+
(let [req (build-request {:url "https://aurl"
113+
:query {:q1 "v1" :q2 "v2"}
114+
:header {:h1 "hv1" :h2 "hv2"}})]
115+
(is (= #{"h1" "h2"}
116+
(-> req .headers .names)))
117+
(is (= #{"q1" "q2"}
118+
(-> req .url .queryParameterNames))))))
110119

111120
(deftest fetching-stuff
112121
(testing "normal response"

0 commit comments

Comments
 (0)