|
40 | 40 |
|
41 | 41 | (deftest ^:integration roundtrip
|
42 | 42 | (run-server)
|
43 |
| - ;; roundtrip with scheme as a keyword |
44 |
| - (let [resp (request {:uri "/get" :method :get})] |
45 |
| - (is (= 200 (:status resp))) |
46 |
| - (is (= "close" (get-in resp [:headers "connection"]))) |
47 |
| - (is (= "get" (:body resp)))) |
48 |
| - ;; roundtrip with scheme as a string |
49 |
| - (let [resp (request {:uri "/get" :method :get |
50 |
| - :scheme "http"})] |
51 |
| - (is (= 200 (:status resp))) |
52 |
| - (is (= "close" (get-in resp [:headers "connection"]))) |
53 |
| - (is (= "get" (:body resp)))) |
54 |
| - (let [params {:a "1" :b "2"}] |
55 |
| - (doseq [[content-type read-fn] |
56 |
| - [[nil (comp parse-form-params slurp)] |
57 |
| - [:x-www-form-urlencoded (comp parse-form-params slurp)] |
58 |
| - [:edn (comp read-string slurp)] |
59 |
| - [:transit+json #(client/parse-transit % :json)] |
60 |
| - [:transit+msgpack #(client/parse-transit % :msgpack)]]] |
61 |
| - (let [resp (request {:uri "/post" |
62 |
| - :as :stream |
63 |
| - :method :post |
64 |
| - :content-type content-type |
65 |
| - :form-params params})] |
66 |
| - (is (= 200 (:status resp))) |
67 |
| - (is (= "close" (get-in resp [:headers "connection"]))) |
68 |
| - (is (= params (read-fn (:body resp))) |
69 |
| - (str "failed with content-type [" content-type "]")))))) |
| 43 | + (testing "roundtrip with scheme as a keyword" |
| 44 | + (let [resp (request {:uri "/get" :method :get})] |
| 45 | + (is (= 200 (:status resp))) |
| 46 | + (is (= "close" (get-in resp [:headers "connection"]))) |
| 47 | + (is (= "get" (:body resp))))) |
| 48 | + (testing "roundtrip with scheme as string" |
| 49 | + (let [resp (request {:uri "/get" :method :get |
| 50 | + :scheme "http"})] |
| 51 | + (is (= 200 (:status resp))) |
| 52 | + (is (= "close" (get-in resp [:headers "connection"]))) |
| 53 | + (is (= "get" (:body resp))))) |
| 54 | + (testing "roundtrip with response parsing" |
| 55 | + (let [params {:a "1" :b "2"}] |
| 56 | + (doseq [[content-type read-fn] |
| 57 | + [[nil (comp parse-form-params slurp)] |
| 58 | + [:x-www-form-urlencoded (comp parse-form-params slurp)] |
| 59 | + [:edn (comp read-string slurp)] |
| 60 | + [:transit+json #(client/parse-transit % :json)] |
| 61 | + [:transit+msgpack #(client/parse-transit % :msgpack)]]] |
| 62 | + (let [resp (request {:uri "/post" |
| 63 | + :as :stream |
| 64 | + :method :post |
| 65 | + :content-type content-type |
| 66 | + :form-params params})] |
| 67 | + (is (= 200 (:status resp))) |
| 68 | + (is (= "close" (get-in resp [:headers "connection"]))) |
| 69 | + (is (= params (read-fn (:body resp))) |
| 70 | + (str "failed with content-type [" content-type "]"))))))) |
70 | 71 |
|
71 | 72 | (deftest ^:integration roundtrip-async
|
72 | 73 | (run-server)
|
73 |
| - ;; roundtrip with scheme as a keyword |
74 |
| - (let [resp (promise) |
75 |
| - exception (promise) |
76 |
| - _ (request {:uri "/get" :method :get |
77 |
| - :async? true} resp exception)] |
78 |
| - (is (= 200 (:status @resp))) |
79 |
| - (is (= "close" (get-in @resp [:headers "connection"]))) |
80 |
| - (is (= "get" (:body @resp))) |
81 |
| - (is (not (realized? exception)))) |
82 |
| - ;; roundtrip with scheme as a string |
83 |
| - (let [resp (promise) |
84 |
| - exception (promise) |
85 |
| - _ (request {:uri "/get" :method :get |
86 |
| - :scheme "http" |
87 |
| - :async? true} resp exception)] |
88 |
| - (is (= 200 (:status @resp))) |
89 |
| - (is (= "close" (get-in @resp [:headers "connection"]))) |
90 |
| - (is (= "get" (:body @resp))) |
91 |
| - (is (not (realized? exception)))) |
92 |
| - |
93 |
| - (let [params {:a "1" :b "2"}] |
94 |
| - (doseq [[content-type read-fn] |
95 |
| - [[nil (comp parse-form-params slurp)] |
96 |
| - [:x-www-form-urlencoded (comp parse-form-params slurp)] |
97 |
| - [:edn (comp read-string slurp)] |
98 |
| - [:transit+json #(client/parse-transit % :json)] |
99 |
| - [:transit+msgpack #(client/parse-transit % :msgpack)]]] |
| 74 | + (testing "roundtrip with scheme as keyword" |
| 75 | + (testing "with async callback arguments" |
100 | 76 | (let [resp (promise)
|
101 | 77 | exception (promise)
|
102 |
| - _ (request {:uri "/post" |
103 |
| - :as :stream |
104 |
| - :method :post |
105 |
| - :content-type content-type |
106 |
| - :flatten-nested-keys [] |
107 |
| - :form-params params |
| 78 | + _ (request {:uri "/get" :method :get |
108 | 79 | :async? true} resp exception)]
|
109 | 80 | (is (= 200 (:status @resp)))
|
110 | 81 | (is (= "close" (get-in @resp [:headers "connection"])))
|
111 |
| - (is (= params (read-fn (:body @resp)))) |
112 |
| - (is (not (realized? exception))))))) |
| 82 | + (is (= "get" (:body @resp))) |
| 83 | + (is (not (realized? exception))))) |
| 84 | + (testing "with respond and raise attributes" |
| 85 | + (let [resp (promise) |
| 86 | + exception (promise) |
| 87 | + _ (request {:uri "/get" :method :get |
| 88 | + :async? true |
| 89 | + :respond resp |
| 90 | + :raise exception |
| 91 | + })] |
| 92 | + (is (= 200 (:status @resp))) |
| 93 | + (is (= "close" (get-in @resp [:headers "connection"]))) |
| 94 | + (is (= "get" (:body @resp))) |
| 95 | + (is (not (realized? exception)))))) |
| 96 | + (testing "round trip with scheme as string" |
| 97 | + (let [resp (promise) |
| 98 | + exception (promise) |
| 99 | + _ (request {:uri "/get" :method :get |
| 100 | + :scheme "http" |
| 101 | + :async? true} resp exception)] |
| 102 | + (is (= 200 (:status @resp))) |
| 103 | + (is (= "close" (get-in @resp [:headers "connection"]))) |
| 104 | + (is (= "get" (:body @resp))) |
| 105 | + (is (not (realized? exception))))) |
| 106 | + (testing "roundtrip with error handling" |
| 107 | + (testing "with async callback arguments" |
| 108 | + (let [resp (promise) |
| 109 | + exception (promise) |
| 110 | + _ (request {:uri "/error" :method :get |
| 111 | + :scheme "http" |
| 112 | + :async? true} resp exception)] |
| 113 | + (is (instance? Exception @exception)))) |
| 114 | + (testing "with respond and raise attributes" |
| 115 | + (let [resp (promise) |
| 116 | + exception (promise) |
| 117 | + _ (request {:uri "/error" :method :get |
| 118 | + :scheme "http" |
| 119 | + :async? true |
| 120 | + :respond resp |
| 121 | + :raise exception})] |
| 122 | + (is (instance? Exception @exception))))) |
| 123 | + (testing "roundtrip with response parsing" |
| 124 | + (testing "with async callback arguments" |
| 125 | + (let [params {:a "1" :b "2"}] |
| 126 | + (doseq [[content-type read-fn] |
| 127 | + [[nil (comp parse-form-params slurp)] |
| 128 | + [:x-www-form-urlencoded (comp parse-form-params slurp)] |
| 129 | + [:edn (comp read-string slurp)] |
| 130 | + [:transit+json #(client/parse-transit % :json)] |
| 131 | + [:transit+msgpack #(client/parse-transit % :msgpack)]]] |
| 132 | + (let [resp (promise) |
| 133 | + exception (promise) |
| 134 | + _ (request {:uri "/post" |
| 135 | + :as :stream |
| 136 | + :method :post |
| 137 | + :content-type content-type |
| 138 | + :flatten-nested-keys [] |
| 139 | + :form-params params |
| 140 | + :async? true} resp exception)] |
| 141 | + (is (= 200 (:status @resp))) |
| 142 | + (is (= "close" (get-in @resp [:headers "connection"]))) |
| 143 | + (is (= params (read-fn (:body @resp)))) |
| 144 | + (is (not (realized? exception))))))) |
| 145 | + |
| 146 | + (testing "with respond and raise attributes" |
| 147 | + (let [params {:a "1" :b "2"}] |
| 148 | + (doseq [[content-type read-fn] |
| 149 | + [[nil (comp parse-form-params slurp)] |
| 150 | + [:x-www-form-urlencoded (comp parse-form-params slurp)] |
| 151 | + [:edn (comp read-string slurp)] |
| 152 | + [:transit+json #(client/parse-transit % :json)] |
| 153 | + [:transit+msgpack #(client/parse-transit % :msgpack)]]] |
| 154 | + (let [resp (promise) |
| 155 | + exception (promise) |
| 156 | + _ (request {:uri "/post" |
| 157 | + :as :stream |
| 158 | + :method :post |
| 159 | + :content-type content-type |
| 160 | + :flatten-nested-keys [] |
| 161 | + :form-params params |
| 162 | + :async? true |
| 163 | + :respond resp |
| 164 | + :raise exception})] |
| 165 | + (is (= 200 (:status @resp))) |
| 166 | + (is (= "close" (get-in @resp [:headers "connection"]))) |
| 167 | + (is (= params (read-fn (:body @resp)))) |
| 168 | + (is (not (realized? exception))))))))) |
113 | 169 |
|
114 | 170 | (def ^:dynamic *test-dynamic-var* nil)
|
115 | 171 |
|
|
0 commit comments