10

mock.request is returning the response :body as a BufferedInputStream. I need to print and compare this as a string. How do I convert it?

When I try to pass response as a message to my assertion, I see a raw output, e.g.

(is (= 200 (:status response) (:body response)))
=> #object[java.io.BufferedInputStream 0x211bdf40 java.io.BufferedInputStream@211bdf40]

Related questions are Java-specific.

Community
  • 1
  • 1
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287

2 Answers2

17

Just slurp it:

(slurp (:body response))
OlegTheCat
  • 4,443
  • 16
  • 24
  • 1
    Thanks. I also had to ensure my API calls returned `(resp/response "some body")` otherwise the response would not be a stream. I.e. Just returning "ok" was just a string and slurp would try to open it as a file. – Petrus Theron Jun 30 '16 at 10:52
2

I tend to use https://github.com/ztellman/byte-streams:

(convert (:body res) String)
DanLebrero
  • 8,545
  • 1
  • 29
  • 30