From a5fc650a0b51bf64cf59234d3073a3862afb289e Mon Sep 17 00:00:00 2001 From: Rahul De Date: Tue, 11 Feb 2020 09:29:02 +0530 Subject: [PATCH] Add more tests for Request building --- src/clj_docker_client/requests.clj | 2 ++ test/clj_docker_client/requests_test.clj | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/clj_docker_client/requests.clj b/src/clj_docker_client/requests.clj index 0aa1ccc..436d20f 100644 --- a/src/clj_docker_client/requests.clj +++ b/src/clj_docker_client/requests.clj @@ -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 diff --git a/test/clj_docker_client/requests_test.clj b/test/clj_docker_client/requests_test.clj index 897c928..1a5d8cc 100644 --- a/test/clj_docker_client/requests_test.clj +++ b/test/clj_docker_client/requests_test.clj @@ -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"