Skip to content

Commit

Permalink
Add more tests for Request building
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Feb 11, 2020
1 parent 276dd35 commit a5fc650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/clj_docker_client/requests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@
req-body (cond
(nil? body)
(RequestBody/create nil "")

(map? body)
(RequestBody/create (json/write-value-as-string body)
(MediaType/get "application/json; charset=utf-8"))

(instance? InputStream body)
(stream->req-body body))
req (case method
Expand Down
21 changes: 15 additions & 6 deletions test/clj_docker_client/requests_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,27 @@
(testing "build a post request with a map body"
(let [req (build-request {:method :post
:url "http://aurl"
:body {:key "value"}})
mime-type (-> req .body .contentType str)]
(is (= "application/json; charset=utf-8" mime-type))))
:body {:key "value"}})]
(is (= "application/json; charset=utf-8"
(-> req .body .contentType str)))))

(testing "build a post request with a stream body"
(let [req (build-request {:method :post
:url "http://aurl"
:body (-> "README.md"
io/file
io/input-stream)})
mime-type (-> req .body .contentType str)]
(is (= "application/octet-stream" mime-type)))))
io/input-stream)})]
(is (= "application/octet-stream"
(-> req .body .contentType str)))))

(testing "build a request with query and header params"
(let [req (build-request {:url "https://aurl"
:query {:q1 "v1" :q2 "v2"}
:header {:h1 "hv1" :h2 "hv2"}})]
(is (= #{"h1" "h2"}
(-> req .headers .names)))
(is (= #{"q1" "q2"}
(-> req .url .queryParameterNames))))))

(deftest fetching-stuff
(testing "normal response"
Expand Down

0 comments on commit a5fc650

Please sign in to comment.