summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Mitchell <brian@p2p.io>2013-12-11 23:07:50 -0500
committerRobert Newson <rnewson@apache.org>2014-08-07 16:39:17 +0100
commit91294eb3fa05da59ed93718a4be2f7fc1bfe9d6a (patch)
treee0db1a08e1d490c9423230fa9743bb9b64a26fb7
parent5b1f7cea04b08fea12364acae72a9898d45212d6 (diff)
downloadcouchdb-91294eb3fa05da59ed93718a4be2f7fc1bfe9d6a.tar.gz
Move attachment code into couch_att
This is moves a majority of the attachment representation into the couch_att module. This serves to isolate the current record to allow easier in-place upgrades as well as a place to start collecting common attachment related functionality. The upgrades are handled lazily to allow rollbacks to older code if the new attachment format has not yet been required via storage of any of the new extended attributes supported by the fetch/store APIs. There are some caveats to this in that the extended attributes are not enforced by couch_att at this time so it'd be quite easy to store garbage. As the extent of attachment concerns becomes more stable, a set of more permanent fetch_[field]/store_[field] functions may be added to help enforce both field types as well as common field names and defaults (all fields will default to undefined except for those defaults present in the orignal record definition, which carry over automatically). Finally, while this patch does move a lot of code to couch_att, it hasn't refined the interfaces much. These changes will follow in later patches to improve and simplify the organization of attachment code. This includes the addition of more unit tests which currently only cover some portions of the attachment functionality related to upgrades and field fetching & storage.
-rwxr-xr-xtest/etap/030-doc-from-json.t38
-rwxr-xr-xtest/etap/031-doc-to-json.t66
2 files changed, 48 insertions, 56 deletions
diff --git a/test/etap/030-doc-from-json.t b/test/etap/030-doc-from-json.t
index 79d5692c7..1a11d8dcb 100755
--- a/test/etap/030-doc-from-json.t
+++ b/test/etap/030-doc-from-json.t
@@ -14,11 +14,7 @@
% License for the specific language governing permissions and limitations under
% the License.
-%% XXX: Figure out how to -include("couch_db.hrl")
--record(doc, {id= <<"">>, revs={0, []}, body={[]},
- atts=[], deleted=false, meta=[]}).
--record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data,
- encoding=identity}).
+-include_lib("couch/include/couch_db.hrl").
main(_) ->
test_util:init_code_path(),
@@ -84,22 +80,22 @@ test_from_json_success() ->
]}}
]}}]},
#doc{atts=[
- #att{
- name = <<"my_attachment.fu">>,
- data = stub,
- type = <<"application/awesome">>,
- att_len = 45,
- disk_len = 45,
- revpos = nil
- },
- #att{
- name = <<"noahs_private_key.gpg">>,
- data = <<"I have a pet fish!">>,
- type = <<"application/pgp-signature">>,
- att_len = 18,
- disk_len = 18,
- revpos = 0
- }
+ couch_att:new([
+ {name, <<"my_attachment.fu">>},
+ {data, stub},
+ {type, <<"application/awesome">>},
+ {att_len, 45},
+ {disk_len, 45},
+ {revpos, undefined}
+ ]),
+ couch_att:new([
+ {name, <<"noahs_private_key.gpg">>},
+ {data, <<"I have a pet fish!">>},
+ {type, <<"application/pgp-signature">>},
+ {att_len, 18},
+ {disk_len, 18},
+ {revpos, 0}
+ ])
]},
"Attachments are parsed correctly."
},
diff --git a/test/etap/031-doc-to-json.t b/test/etap/031-doc-to-json.t
index e0aaf70d5..d4227e7dd 100755
--- a/test/etap/031-doc-to-json.t
+++ b/test/etap/031-doc-to-json.t
@@ -14,11 +14,7 @@
% License for the specific language governing permissions and limitations under
% the License.
-%% XXX: Figure out how to -include("couch_db.hrl")
--record(doc, {id= <<"">>, revs={0, []}, body={[]},
- atts=[], deleted=false, meta=[]}).
--record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data,
- encoding=identity}).
+-include_lib("couch/include/couch_db.hrl").
main(_) ->
test_util:init_code_path(),
@@ -114,22 +110,22 @@ test_to_json_success() ->
},
{
#doc{atts=[
- #att{
- name = <<"big.xml">>,
- type = <<"xml/sucks">>,
- data = fun() -> ok end,
- revpos = 1,
- att_len = 400,
- disk_len = 400
- },
- #att{
- name = <<"fast.json">>,
- type = <<"json/ftw">>,
- data = <<"{\"so\": \"there!\"}">>,
- revpos = 1,
- att_len = 16,
- disk_len = 16
- }
+ couch_att:new([
+ {name, <<"big.xml">>},
+ {type, <<"xml/sucks">>},
+ {data, fun() -> ok end},
+ {revpos, 1},
+ {att_len, 400},
+ {disk_len, 400}
+ ]),
+ couch_att:new([
+ {name, <<"fast.json">>},
+ {type, <<"json/ftw">>},
+ {data, <<"{\"so\": \"there!\"}">>},
+ {revpos, 1},
+ {att_len, 16},
+ {disk_len, 16}
+ ])
]},
{[
{<<"_id">>, <<>>},
@@ -153,20 +149,20 @@ test_to_json_success() ->
{
[attachments],
#doc{atts=[
- #att{
- name = <<"stuff.txt">>,
- type = <<"text/plain">>,
- data = fun() -> <<"diet pepsi">> end,
- revpos = 1,
- att_len = 10,
- disk_len = 10
- },
- #att{
- name = <<"food.now">>,
- type = <<"application/food">>,
- revpos = 1,
- data = <<"sammich">>
- }
+ couch_att:new([
+ {name, <<"stuff.txt">>},
+ {type, <<"text/plain">>},
+ {data, fun() -> <<"diet pepsi">> end},
+ {revpos, 1},
+ {att_len, 10},
+ {disk_len, 10}
+ ]),
+ couch_att:new([
+ {name, <<"food.now">>},
+ {type, <<"application/food">>},
+ {revpos, 1},
+ {data, <<"sammich">>}
+ ])
]},
{[
{<<"_id">>, <<>>},