From 1be12947c878bbbf28b24a1a330e336272fa3b06 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 17 Jan 2009 13:25:49 +0000 Subject: Add some tests for using _attachments in views. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@735284 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch_tests.js | 98 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) (limited to 'share/www') diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 81609f19..f292bb1f 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -1010,7 +1010,7 @@ var tests = { var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc4/attachment.txt"); T(xhr.status == 200); T(xhr.responseText == "This is a string"); - + }, attachment_paths : function(debug) { @@ -1147,6 +1147,93 @@ var tests = { }, + attachment_views: function(debug) { + + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + // count attachments in a view + + db.bulkSave(makeDocs(0, 10)); + + db.bulkSave(makeDocs(10, 20, { + _attachments:{ + "foo.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + })); + + db.bulkSave(makeDocs(20, 30, { + _attachments:{ + "foo.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + }, + "bar.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + })); + + db.bulkSave(makeDocs(30, 40, { + _attachments:{ + "foo.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + }, + "bar.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + }, + "baz.txt": { + content_type:"text/plain", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + })); + + var mapFunction = function(doc) { + var count = 0; + + for(var idx in doc._attachments) { + count = count + 1; + } + + emit(parseInt(doc._id), count); + } + + var reduceFunction = function(key, values) { + return sum(values); + } + + var result = db.query(mapFunction, reduceFunction); + + T(result.rows.length == 1); + T(result.rows[0].value == 60); + + var result = db.query(mapFunction, reduceFunction, { + startkey:10, + endkey:19 + }); + + T(result.rows.length == 1); + T(result.rows[0].value == 10); + + var result = db.query(mapFunction, reduceFunction, { + startkey:20, + endkey:29 + }); + + T(result.rows.length == 1); + T(result.rows[0].value == 20); + + }, + design_paths : function(debug) { var db = new CouchDB("test_suite_db"); db.deleteDb(); @@ -2096,7 +2183,14 @@ var tests = { for(test in repTests) if(repTests[test].init) repTests[test].init(dbA, dbB); - T(CouchDB.replicate(A, B).ok); + try { + T(CouchDB.replicate(A, B).ok); + } catch (e) { + if(window.location.host.match(/localhost/)) { + alert("Hi, the replication test failed. The most likely cause is that 'localhost' resolves to ::1 (IPv6) and CouchDB only listenes at 127.0.0.1 (IPv4). Try 127.0.0.1 to access Futon and run this test suite again."); + } + throw e; + } for(test in repTests) if(repTests[test].afterAB1) repTests[test].afterAB1(dbA, dbB); -- cgit v1.2.3