couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [13/25] couch commit: updated refs/heads/master to 92598cd
Date Thu, 15 Oct 2015 16:35:47 GMT
Add test case for doc_to_multi_part_stream


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/4abf06ee
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/4abf06ee
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/4abf06ee

Branch: refs/heads/master
Commit: 4abf06ee1fe936e1facd7cdbd187a95391d1aafe
Parents: f8e7d61
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Nov 28 10:05:22 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed May 6 06:55:58 2015 -0700

----------------------------------------------------------------------
 test/couch_doc_tests.erl | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4abf06ee/test/couch_doc_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_tests.erl b/test/couch_doc_tests.erl
index 5a3f79f..1ccf2b8 100644
--- a/test/couch_doc_tests.erl
+++ b/test/couch_doc_tests.erl
@@ -33,8 +33,46 @@ doc_from_multi_part_stream_test() ->
         couch_doc:doc_from_multi_part_stream(ContentType, DataFun),
     ok.
 
+doc_to_multi_part_stream_test() ->
+    Boundary = <<"multipart_related_boundary~~~~~~~~~~~~~~~~~~~~">>,
+    JsonBytes = <<"{\n \"_id\": \"our document goes here\"\n}\n\n">>,
+    ContentType = "multipart/related;boundary=multipart_related_boundary~~~~~~~~~~~~~~~~~~~~",
+    AttData = <<"Hello my important document">>,
+    AttLength = size(AttData),
+    Atts = [couch_att:new([
+       {name, <<"test">>}, {data, AttData}, {type, <<"text/plain">>},
+       {att_len, AttLength}, {disk_len, AttLength}])],
+    couch_doc:doc_to_multi_part_stream(Boundary, JsonBytes, Atts, fun send/1, true),
+    AttLengthStr = integer_to_binary(AttLength),
+    BoundaryLen = size(Boundary),
+    [
+     <<"--", Boundary/binary>>,
+     <<"Content-Type: application/json">>,
+     <<>>,
+     JsonBytes,
+     <<"--", Boundary/binary>>,
+     <<"Content-Disposition: attachment; filename=\"test\"">>,
+     <<"Content-Type: text/plain">>,
+     <<"Content-Length: ", AttLengthStr/binary>>,
+     <<>>,
+     AttData,
+     <<"--", Boundary:BoundaryLen/binary, "--">>
+    ] = collected(),
+    ok.
+
 request(start) ->
     {ok, Doc} = file:read_file(?REQUEST_FIXTURE),
     {Doc, fun() -> request(stop) end};
 request(stop) ->
     {"", fun() -> request(stop) end}.
+
+send(Data) ->
+    send(Data, get(data)).
+send(Data, undefined) ->
+    send(Data, []);
+send(Data, Acc) ->
+    put(data, [Acc|Data]).
+
+collected() ->
+    B = binary:replace(iolist_to_binary(get(data)), <<"\r\n">>, <<0>>,
[global]),
+    binary:split(B, [<<0>>], [global]).


Mime
View raw message