Skip to content
This repository
Browse code

fix test error

  • Loading branch information...
commit 141ba840200876a238255f07960c816a3e45230a 1 parent 02a9c8b
Sun Ning authored
2  src/slacker/server/http.clj
@@ -43,7 +43,7 @@
43 43 :body "rejected by access control list"}
44 44 ;; normal response packet
45 45 (let [[ct code result] (second resp-body)
46   - content-type (str "application/" (str ct))
  46 + content-type (str "application/" (name ct))
47 47 status (case code
48 48 :success 200
49 49 :exception 500
24 test/slacker/test/server/http.clj
... ... @@ -1,12 +1,11 @@
1 1 (ns slacker.test.server.http
2 2 (:use clojure.test)
  3 + (:use [slacker.common :only [version]] )
3 4 (:use slacker.server.http)
  5 + (:use slacker.serialization)
4 6 (:require [clojure.java.io :as io])
5 7 (:import [java.io ByteArrayOutputStream]))
6 8
7   -(defn fake-server-handler [req]
8   - (assoc req :code :success :result (:data req)))
9   -
10 9 (defn make-fake-data-stream [string-data]
11 10 (io/input-stream (.getBytes string-data "UTF-8")))
12 11
@@ -15,13 +14,20 @@
15 14 (io/copy bis bos)
16 15 (String. (.toByteArray bos) "UTF-8")))
17 16
18   -(deftest test-http
19   - (let [handler (wrap-http-server-handler fake-server-handler)
20   - in-data "[27 89]"
  17 +(deftest test-http-request
  18 + (let [in-data "[27 89]"
21 19 req {:uri "/echo.clj" :body (make-fake-data-stream in-data)}
22   - resp (handler req)]
  20 + sreq (ring-req->slacker-req req)]
  21 + (is (= version (first sreq)))
  22 + (is (= :type-request (-> sreq (nth 2) first)))
  23 + (is (= :clj (-> sreq (nth 2) second first)))
  24 + (is (= "echo" (-> sreq (nth 2) second second)))))
  25 +
  26 +(deftest test-http-response
  27 + (let [result (serialize :clj [1])
  28 + sresp [version 0 [:type-response [:clj :success result]]]
  29 + resp (slacker-resp->ring-resp sresp)]
23 30 (is (= 200 (:status resp)))
24   - (is (= in-data (byteins->string (:body resp))))
25   - (is (= "application/clj" (get (:headers resp) "content-type")))))
  31 + (is (= "application/clj" (-> resp :headers (get "content-type"))))))
26 32
27 33

0 comments on commit 141ba84

Please sign in to comment.
Something went wrong with that request. Please try again.