testing octet-stream file uploads

182 views
Skip to first unread message

Rowland Watkins

unread,
Feb 28, 2021, 11:49:48 AM2/28/21
to pedestal-users

Hi folks,

I'm wondering if anyone here has some tips on passing a multipart octet-stream, during an integration test, using io.pedestal.test.response-for? Here's what I have so far:

(let [url "/product"
        b (str "--XXXX\r\n"
               "Content-Disposition: form-data;"
               "name=\"image\"; filename=\"aardvark.png\"\r\n"
               "Content-Type: image/png\r\n\r\n"
               "foo\r\n"
               "--XXXX--")
        h {"Content-Type" "multipart/form-data; boundary=XXXX"          
           "Accept" "application/edn"}]    
    (response-for
     service
     :post url 
     :body b
     :headers h))

The above code works fine - "foo" is the file content, which is a String. My challenge now is taking an entire application/octet-stream in the above example, and passing it as the :body to response-for. response-for seems to only want a String, as per https://github.com/pedestal/pedestal/blob/master/service/src/io/pedestal/test.clj, even though TestRequestBody protocol supports InputStream.

When I attempt to read the raw HTTP multipart request (recorded by Fiddler2) from a file, clojure.io/input-stream will initialise a BufferedInputStream. Upon passing the InputStream as the :body in response-for, I get the following exception:

java.lang.IllegalArgumentException: Cannot open <nil> as an InputStream.

My guess is that the interceptor-service-fn doesn't like what is passed to it when creating the dummy servlet request from the body.

Perhaps I'm taking the wrong approach here, any tips would be most appreciated, many thanks!

Cheers,

Rowland


Reply all
Reply to author
Forward
0 new messages