Created
April 13, 2017 19:49
-
-
Save DanBurton/4f27863b57b957d86cc9a1b77a5ba645 to your computer and use it in GitHub Desktop.
Passing tests wrt form-params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (defproject clj-http-bug "0.1.0-SNAPSHOT" | |
;; :description "FIXME: write description" | |
;; :url "http://example.com/FIXME" | |
;; :license {:name "Eclipse Public License" | |
;; :url "http://www.eclipse.org/legal/epl-v10.html"} | |
;; :dependencies [[org.clojure/clojure "1.8.0"] | |
;; [clj-http "2.3.0"] | |
;; [http-kit "2.2.0"] | |
;; [ring/ring-jetty-adapter "1.5.1"]]) | |
(ns clj-http-bug.core-test | |
(:require | |
[clojure.test :refer :all] | |
[ring.adapter.jetty :as jetty] | |
[ring.middleware.params :as middleware] | |
[clj-http.client :as clj-http] | |
[org.httpkit.client :as httpkit])) | |
(def last-request (atom nil)) | |
(def port 3333) | |
(defn handler [request] | |
(reset! last-request request) | |
{:status 200}) | |
(defn server [] | |
(jetty/run-jetty (middleware/wrap-params handler) | |
{:port port :join? false})) | |
(defn with-server [f] | |
(let [s (server)] | |
(try | |
(f) | |
(finally (.stop s))))) | |
(def url (str "http://localhost:" port "/")) | |
(def form-params {"foo[]" ["foo1" "foo2"]}) | |
(def request | |
{:url url | |
:method :post | |
:form-params form-params}) | |
(use-fixtures :once with-server) | |
(deftest clj-http-test | |
(testing "clj-http sends form params" | |
(reset! last-request nil) | |
(clj-http/request request) | |
(is (= form-params (:form-params @last-request))))) | |
(deftest httpkit-test | |
(testing "httpkit sends form params" | |
(reset! last-request nil) | |
@(httpkit/request request) | |
(is (= form-params (:form-params @last-request))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment