Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Apr 21, 2012
1 parent 02a9c8b commit 141ba84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/slacker/server/http.clj
Expand Up @@ -43,7 +43,7 @@
:body "rejected by access control list"} :body "rejected by access control list"}
;; normal response packet ;; normal response packet
(let [[ct code result] (second resp-body) (let [[ct code result] (second resp-body)
content-type (str "application/" (str ct)) content-type (str "application/" (name ct))
status (case code status (case code
:success 200 :success 200
:exception 500 :exception 500
Expand Down
24 changes: 15 additions & 9 deletions test/slacker/test/server/http.clj
@@ -1,12 +1,11 @@
(ns slacker.test.server.http (ns slacker.test.server.http
(:use clojure.test) (:use clojure.test)
(:use [slacker.common :only [version]] )
(:use slacker.server.http) (:use slacker.server.http)
(:use slacker.serialization)
(:require [clojure.java.io :as io]) (:require [clojure.java.io :as io])
(:import [java.io ByteArrayOutputStream])) (:import [java.io ByteArrayOutputStream]))


(defn fake-server-handler [req]
(assoc req :code :success :result (:data req)))

(defn make-fake-data-stream [string-data] (defn make-fake-data-stream [string-data]
(io/input-stream (.getBytes string-data "UTF-8"))) (io/input-stream (.getBytes string-data "UTF-8")))


Expand All @@ -15,13 +14,20 @@
(io/copy bis bos) (io/copy bis bos)
(String. (.toByteArray bos) "UTF-8"))) (String. (.toByteArray bos) "UTF-8")))


(deftest test-http (deftest test-http-request
(let [handler (wrap-http-server-handler fake-server-handler) (let [in-data "[27 89]"
in-data "[27 89]"
req {:uri "/echo.clj" :body (make-fake-data-stream in-data)} req {:uri "/echo.clj" :body (make-fake-data-stream in-data)}
resp (handler req)] sreq (ring-req->slacker-req req)]
(is (= version (first sreq)))
(is (= :type-request (-> sreq (nth 2) first)))
(is (= :clj (-> sreq (nth 2) second first)))
(is (= "echo" (-> sreq (nth 2) second second)))))

(deftest test-http-response
(let [result (serialize :clj [1])
sresp [version 0 [:type-response [:clj :success result]]]
resp (slacker-resp->ring-resp sresp)]
(is (= 200 (:status resp))) (is (= 200 (:status resp)))
(is (= in-data (byteins->string (:body resp)))) (is (= "application/clj" (-> resp :headers (get "content-type"))))))
(is (= "application/clj" (get (:headers resp) "content-type")))))




0 comments on commit 141ba84

Please sign in to comment.