diff options
Diffstat (limited to 'share/www/script/test')
34 files changed, 334 insertions, 335 deletions
| diff --git a/share/www/script/test/all_docs.js b/share/www/script/test/all_docs.js index 3dd3aa53..fcec3b43 100644 --- a/share/www/script/test/all_docs.js +++ b/share/www/script/test/all_docs.js @@ -15,7 +15,7 @@ couchTests.all_docs = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    // Create some more documents.    // Notice the use of the ok member on the return result.    T(db.save({_id:"0",a:1,b:1}).ok); @@ -32,7 +32,7 @@ couchTests.all_docs = function(debug) {    for(var i=0; i < rows.length; i++) {      T(rows[i].id >= "0" && rows[i].id <= "4");    } -   +    // Check _all_docs with descending=true    var desc = db.allDocs({descending:true});    T(desc.total_rows == desc.rows.length); @@ -40,7 +40,7 @@ couchTests.all_docs = function(debug) {    // Check _all_docs offset    var all = db.allDocs({startkey:"2"});    T(all.offset == 2); -   +    // check that the docs show up in the seq view in the order they were created    var all_seq = db.allDocsBySeq();    var ids = ["0","3","1","2"]; @@ -48,7 +48,7 @@ couchTests.all_docs = function(debug) {      var row = all_seq.rows[i];      T(row.id == ids[i]);    }; -   +    // it should work in reverse as well    all_seq = db.allDocsBySeq({descending:true});    ids = ["2","1","3","0"]; @@ -56,13 +56,13 @@ couchTests.all_docs = function(debug) {      var row = all_seq.rows[i];      T(row.id == ids[i]);    }; -   +    // check that deletions also show up right    var doc1 = db.open("1");    var deleted = db.deleteDoc(doc1);    T(deleted.ok);    all_seq = db.allDocsBySeq(); -   +    // the deletion should make doc id 1 have the last seq num    T(all_seq.rows.length == 4);    T(all_seq.rows[3].id == "1"); @@ -70,13 +70,13 @@ couchTests.all_docs = function(debug) {    // is this a bug?    // T(all_seq.rows.length == all_seq.total_rows); -   +    // do an update    var doc2 = db.open("3");    doc2.updated = "totally";    db.save(doc2);    all_seq = db.allDocsBySeq(); -   +    // the update should make doc id 3 have the last seq num    T(all_seq.rows.length == 4);    T(all_seq.rows[3].id == "3"); @@ -90,7 +90,7 @@ couchTests.all_docs = function(debug) {    // and on the deleted one, no doc    T(all_seq.rows[2].value.deleted);    T(!all_seq.rows[2].doc); -   +    // test the all docs collates sanely    db.save({_id: "Z", foo: "Z"});    db.save({_id: "a", foo: "a"}); diff --git a/share/www/script/test/attachment_names.js b/share/www/script/test/attachment_names.js index 3c694dd0..f9c846eb 100644 --- a/share/www/script/test/attachment_names.js +++ b/share/www/script/test/attachment_names.js @@ -10,21 +10,21 @@  // License for the specific language governing permissions and limitations under  // the License. -couchTests.attachment_names = function(debug) {  -  var db = new CouchDB("test_suite_db");  -  db.deleteDb();  -  db.createDb();  -  if (debug) debugger;  - -  var binAttDoc = {  -    _id: "bin_doc",  -    _attachments:{  -      "foo\x80txt": {  -        content_type:"text/plain",  -        data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="  -      }  -    }  -  }  +couchTests.attachment_names = function(debug) { +  var db = new CouchDB("test_suite_db"); +  db.deleteDb(); +  db.createDb(); +  if (debug) debugger; + +  var binAttDoc = { +    _id: "bin_doc", +    _attachments:{ +      "foo\x80txt": { +        content_type:"text/plain", +        data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" +      } +    } +  }    // inline attachments    try { @@ -38,7 +38,7 @@ couchTests.attachment_names = function(debug) {    // standalone docs    var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])}    ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np"; -   +    var xhr = (CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment\x80txt", {      headers:{"Content-Type":"text/plain;charset=utf-8"},      body:bin_data @@ -64,15 +64,15 @@ couchTests.attachment_names = function(debug) {    // leading underscores -  var binAttDoc = {  -    _id: "bin_doc2",  -    _attachments:{  -      "_foo.txt": {  -        content_type:"text/plain",  -        data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="  -      }  -    }  -  }  +  var binAttDoc = { +    _id: "bin_doc2", +    _attachments:{ +      "_foo.txt": { +        content_type:"text/plain", +        data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" +      } +    } +  }    try {      db.save(binAttDoc); @@ -80,8 +80,8 @@ couchTests.attachment_names = function(debug) {    } catch (e) {      TEquals("bad_request", e.error, "attachment_name: leading underscore");      TEquals("Attachment name can't start with '_'", e.reason, "attachment_name: leading underscore"); -  }   -   +  } +    // todo: form uploads, waiting for cmlenz' test case for form uploads  }; diff --git a/share/www/script/test/attachment_paths.js b/share/www/script/test/attachment_paths.js index ef9fa869..245d2949 100644 --- a/share/www/script/test/attachment_paths.js +++ b/share/www/script/test/attachment_paths.js @@ -44,14 +44,14 @@ couchTests.attachment_paths = function(debug) {      // lets try it with an escaped attachment id...      // weird that it's at two urls      var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo%2Fbar.txt"); -    T(xhr.status == 200);  +    T(xhr.status == 200);      // xhr.responseText == "This is a base64 encoded text"      var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo/baz.txt");      T(xhr.status == 404);      var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo%252Fbaz.txt"); -    T(xhr.status == 200);  +    T(xhr.status == 200);      T(xhr.responseText == "We like percent two F.");      // require a _rev to PUT @@ -59,7 +59,7 @@ couchTests.attachment_paths = function(debug) {        headers:{"Content-Type":"text/plain;charset=utf-8"},        body:"Just some text"      }); -    T(xhr.status == 409);     +    T(xhr.status == 409);      var xhr = CouchDB.request("PUT", "/"+dbName+"/bin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {        body:"This is no base64 encoded text", @@ -77,7 +77,7 @@ couchTests.attachment_paths = function(debug) {      T(binAttDoc._attachments["foo/bar2.txt"].length == 30);      //// now repeat the while thing with a design doc -   +      // first just save a regular doc with an attachment that has a slash in the url.      // (also gonna run an encoding check case)      var binAttDoc = { @@ -120,7 +120,7 @@ couchTests.attachment_paths = function(debug) {      T(xhr.status == 404);      var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo%252Fbaz.txt"); -    T(xhr.status == 200);  +    T(xhr.status == 200);      T(xhr.responseText == "We like percent two F.");      // require a _rev to PUT @@ -128,7 +128,7 @@ couchTests.attachment_paths = function(debug) {        headers:{"Content-Type":"text/plain;charset=utf-8"},        body:"Just some text"      }); -    T(xhr.status == 409);     +    T(xhr.status == 409);      var xhr = CouchDB.request("PUT", "/"+dbName+"/_design%2Fbin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {        body:"This is no base64 encoded text", diff --git a/share/www/script/test/attachment_views.js b/share/www/script/test/attachment_views.js index b97a4130..903fbc4c 100644 --- a/share/www/script/test/attachment_views.js +++ b/share/www/script/test/attachment_views.js @@ -73,7 +73,7 @@ couchTests.attachment_views= function(debug) {    var reduceFunction = function(key, values) {      return sum(values);    } -   +    var result = db.query(mapFunction, reduceFunction);    T(result.rows.length == 1); diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js index e68cd444..6af6ae8f 100644 --- a/share/www/script/test/attachments.js +++ b/share/www/script/test/attachments.js @@ -33,7 +33,7 @@ couchTests.attachments= function(debug) {    T(xhr.responseText == "This is a base64 encoded text");    T(xhr.getResponseHeader("Content-Type") == "text/plain");    T(xhr.getResponseHeader("Etag") == '"' + save_response.rev + '"'); -   +    // empty attachment    var binAttDoc2 = {      _id: "bin_doc2", @@ -70,7 +70,7 @@ couchTests.attachments= function(debug) {    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc2/foo2.txt");    T(xhr.responseText == "This is no base64 encoded text");    T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8"); -   +    // test without rev, should fail    var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt");    T(xhr.status == 409); @@ -78,8 +78,8 @@ couchTests.attachments= function(debug) {    // test with rev, should not fail    var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt?rev=" + rev);    T(xhr.status == 200); -   -   + +    // test binary data    var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])}    ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np";    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment.txt", { @@ -88,11 +88,11 @@ couchTests.attachments= function(debug) {    });    T(xhr.status == 201);    var rev = JSON.parse(xhr.responseText).rev; -   +    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt");    T(xhr.responseText == bin_data);    T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8"); -   +    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment.txt", {      headers:{"Content-Type":"text/plain;charset=utf-8"},      body:bin_data @@ -116,7 +116,7 @@ couchTests.attachments= function(debug) {    var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);    T(xhr.status == 200); -   +    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt");    T(xhr.status == 404); @@ -137,7 +137,7 @@ couchTests.attachments= function(debug) {    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc4/attachment.txt");    T(xhr.status == 200);    T(xhr.responseText.length == 0); -   +    // overwrite previsously empty attachment    var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc4/attachment.txt?rev=" + rev, {      headers:{"Content-Type":"text/plain;charset=utf-8"}, @@ -148,8 +148,8 @@ couchTests.attachments= function(debug) {    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc4/attachment.txt");    T(xhr.status == 200);    T(xhr.responseText == "This is a string"); -   -   + +    // Attachment sparseness COUCHDB-220    var docs = [] @@ -167,7 +167,7 @@ couchTests.attachments= function(debug) {    }    db.bulkSave(docs); -   +    var before = db.info().disk_size;    // Compact it. @@ -175,14 +175,14 @@ couchTests.attachments= function(debug) {    T(db.last_req.status == 202);    // compaction isn't instantaneous, loop until done    while (db.info().compact_running) {}; -   +    var after = db.info().disk_size; -   +    // Compaction should reduce the database slightly, but not    // orders of magnitude (unless attachments introduce sparseness)    T(after > before * 0.1, "before: " + before + " after: " + after); -   -   + +    // test large attachments - COUCHDB-366    var lorem = CouchDB.request("GET", "/_utils/script/test/lorem.txt").responseText; diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js index 47e94d2c..62ac2df9 100644 --- a/share/www/script/test/basics.js +++ b/share/www/script/test/basics.js @@ -13,7 +13,7 @@  // Do some basic tests.  couchTests.basics = function(debug) {      var result = JSON.parse(CouchDB.request("GET", "/").responseText); -    T(result.couchdb == "Welcome");  +    T(result.couchdb == "Welcome");      var db = new CouchDB("test_suite_db");      db.deleteDb(); @@ -31,11 +31,11 @@ couchTests.basics = function(debug) {      // creating a new DB should return Location header      xhr = CouchDB.request("DELETE", "/test_suite_db");      xhr = CouchDB.request("PUT", "/test_suite_db"); -    TEquals("/test_suite_db",  +    TEquals("/test_suite_db",        xhr.getResponseHeader("Location").substr(-14),        "should return Location header to newly created document"); -    TEquals("http://",  +    TEquals("http://",        xhr.getResponseHeader("Location").substr(0, 7),        "should return absolute Location header to newly created document"); @@ -66,7 +66,7 @@ couchTests.basics = function(debug) {      // make sure you can do a seq=true option      var doc = db.open(id, {local_seq:true});      T(doc._local_seq == 1); -     +      // Create some more documents.      // Notice the use of the ok member on the return result. @@ -161,11 +161,11 @@ couchTests.basics = function(debug) {      var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {        body: JSON.stringify({"a":1})      }); -    TEquals("/test_suite_db/newdoc",  +    TEquals("/test_suite_db/newdoc",        xhr.getResponseHeader("Location").substr(-21),        "should return Location header to newly created document"); -    TEquals("http://",  +    TEquals("http://",        xhr.getResponseHeader("Location").substr(0, 7),        "should return absolute Location header to newly created document"); @@ -182,12 +182,12 @@ couchTests.basics = function(debug) {    ]    var test_doc = function(info) {      var data = JSON.stringify(info[1]); -     +      xhr = CouchDB.request("PUT", "/test_suite_db/" + info[0], {body: data});      T(xhr.status == 500);      result = JSON.parse(xhr.responseText);      T(result.error == "doc_validation"); -     +      xhr = CouchDB.request("POST", "/test_suite_db/", {body: data});      T(xhr.status == 500);      result = JSON.parse(xhr.responseText); diff --git a/share/www/script/test/batch_save.js b/share/www/script/test/batch_save.js index 77aa6635..d2721901 100644 --- a/share/www/script/test/batch_save.js +++ b/share/www/script/test/batch_save.js @@ -19,32 +19,32 @@ couchTests.batch_save = function(debug) {    // commit should work fine with no batches    T(db.ensureFullCommit().ok); -   +    // PUT a doc with ?batch=ok    T(db.save({_id:"0",a:1,b:1},  {batch : "ok"}).ok);    // test that response is 200 Accepted    T(db.last_req.status == 202);    T(db.last_req.statusText == "Accepted"); -   +    T(db.allDocs().total_rows == 0);    restartServer(); -   +    // lost the updates    T(db.allDocs().total_rows == 0); -   +    T(db.save({_id:"0",a:1,b:1},  {batch : "ok"}).ok);    T(db.save({_id:"1",a:1,b:1},  {batch : "ok"}).ok);    T(db.save({_id:"2",a:1,b:1},  {batch : "ok"}).ok);    T(db.ensureFullCommit().ok);    T(db.allDocs().total_rows == 3); -   +    // repeat the tests for POST    var resp = db.request("POST", db.uri + "?batch=ok", {body: JSON.stringify({a:1})});    T(JSON.parse(resp.responseText).ok); -   +    // test that response is 200 Accepted    T(resp.status == 202);    T(resp.statusText == "Accepted"); @@ -59,5 +59,5 @@ couchTests.batch_save = function(debug) {    T(db.ensureFullCommit().ok);    T(db.allDocs().total_rows == 5); -   +  }; diff --git a/share/www/script/test/bulk_docs.js b/share/www/script/test/bulk_docs.js index 8e73ded4..b4c0ef9d 100644 --- a/share/www/script/test/bulk_docs.js +++ b/share/www/script/test/bulk_docs.js @@ -34,7 +34,7 @@ couchTests.bulk_docs = function(debug) {    T(results.length == 5);    for (i = 0; i < 5; i++) {      T(results[i].id == i.toString()); -     +      // set the delete flag to delete the docs in the next step      docs[i]._deleted = true;    } @@ -72,7 +72,7 @@ couchTests.bulk_docs = function(debug) {    // Now save the bulk docs, When we use all_or_nothing, we don't get conflict    // checking, all docs are saved regardless of conflict status, or none are    // saved. -  results = db.bulkSave(docs,{all_or_nothing:true});   +  results = db.bulkSave(docs,{all_or_nothing:true});    T(results.error === undefined);    var doc = db.open("0", {conflicts:true}); @@ -88,8 +88,8 @@ couchTests.bulk_docs = function(debug) {    T(results[0].id != "");    T(results[0].rev != ""); -   -   + +    // Regression test for failure on update/delete    var newdoc = {"_id": "foobar", "body": "baz"};    T(db.save(newdoc).ok); diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js index 98f31d6f..6ae035fa 100644 --- a/share/www/script/test/changes.js +++ b/share/www/script/test/changes.js @@ -16,98 +16,98 @@ couchTests.changes = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    var req = CouchDB.request("GET", "/test_suite_db/_changes");    var resp = JSON.parse(req.responseText); -   +    T(resp.results.length == 0 && resp.last_seq==0) -   +    var docFoo = {_id:"foo", bar:1};    db.save(docFoo); -   +    req = CouchDB.request("GET", "/test_suite_db/_changes");    var resp = JSON.parse(req.responseText); -   +    T(resp.results.length == 1 && resp.last_seq==1)    T(resp.results[0].changes[0].rev == docFoo._rev) -   +    req = CouchDB.request("GET", "/test_suite_db/_changes?continuous=true&timeout=10");    var resp = JSON.parse(req.responseText);    T(resp.results.length == 1 && resp.last_seq==1)    T(resp.results[0].changes[0].rev == docFoo._rev) -   +    var xhr; -   +    try {      xhr = CouchDB.newXhr(); -  } catch (err) {   +  } catch (err) {    } -   +    if (xhr) {      // Only test the continuous stuff if we have a real XHR object      // with real async support. -     +      var sleep = function(msecs) {        // by making a slow sync request, we allow the waiting XHR request data        // to be received.        var req = CouchDB.request("GET", "/_sleep?time=" + msecs);        T(JSON.parse(req.responseText).ok == true);      } -   +      var parse_changes_line = function(line) {        if (line.charAt(line.length-1) == ",") {          line = line.substring(0, line.length-1);        }        return JSON.parse(line);      } -     -   + +      xhr.open("GET", "/test_suite_db/_changes?continuous=true", true);      xhr.send(""); -   +      var docBar = {_id:"bar", bar:1};      db.save(docBar); -   +      sleep(100);      var lines = xhr.responseText.split("\n"); -   +      T(lines[0]='{"results":['); -   +      var change = parse_changes_line(lines[1]); -   +      T(change.seq == 1)      T(change.id == "foo") -   +      change = parse_changes_line(lines[2]); -   +      T(change.seq == 2)      T(change.id == "bar")      T(change.changes[0].rev == docBar._rev) -   +      var docBaz = {_id:"baz", baz:1};      db.save(docBaz); -   +      sleep(100);      var lines = xhr.responseText.split("\n"); -   +      change = parse_changes_line(lines[3]); -   +      T(change.seq == 3);      T(change.id == "baz");      T(change.changes[0].rev == docBaz._rev); -     -     + +      xhr = CouchDB.newXhr(); -   +      //verify the hearbeat newlines are sent      xhr.open("GET", "/test_suite_db/_changes?continuous=true&heartbeat=10", true);      xhr.send(""); -     +      sleep(100); -     +      var str = xhr.responseText; -     +      T(str.charAt(str.length - 1) == "\n")      T(str.charAt(str.length - 2) == "\n")    } diff --git a/share/www/script/test/compact.js b/share/www/script/test/compact.js index a3b55d85..2add707e 100644 --- a/share/www/script/test/compact.js +++ b/share/www/script/test/compact.js @@ -43,7 +43,7 @@ couchTests.compact = function(debug) {    T(db.last_req.status == 202);    // compaction isn't instantaneous, loop until done    while (db.info().compact_running) {}; -   +    T(db.ensureFullCommit().ok);    restartServer();    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt"); @@ -51,5 +51,5 @@ couchTests.compact = function(debug) {    T(xhr.getResponseHeader("Content-Type") == "text/plain")    T(db.info().doc_count == 1);    T(db.info().disk_size < deletesize); -   +  }; diff --git a/share/www/script/test/conflicts.js b/share/www/script/test/conflicts.js index dfd7e8b6..d556acd7 100644 --- a/share/www/script/test/conflicts.js +++ b/share/www/script/test/conflicts.js @@ -41,7 +41,7 @@ couchTests.conflicts = function(debug) {    } catch (e) {      T(e.error == "conflict");    } -    +    var bySeq = db.allDocsBySeq();    T( bySeq.rows.length == 1) diff --git a/share/www/script/test/delayed_commits.js b/share/www/script/test/delayed_commits.js index 0ead2d84..1cc0b339 100644 --- a/share/www/script/test/delayed_commits.js +++ b/share/www/script/test/delayed_commits.js @@ -15,43 +15,43 @@ couchTests.delayed_commits = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    // By default, couchdb doesn't fully commit documents to disk right away, -  // it waits about a second to batch the full commit flush along with any  +  // it waits about a second to batch the full commit flush along with any    // other updates. If it crashes or is restarted you may lose the most    // recent commits. -   +    T(db.save({_id:"1",a:2,b:4}).ok);    T(db.open("1") != null); -   +    restartServer(); -   +    T(db.open("1") == null); // lost the update.    // note if we waited > 1 sec before the restart, the doc would likely    // commit. -   -   + +    // Retry the same thing but with full commits on. -   +    var db2 = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"}); -   +    T(db2.save({_id:"1",a:2,b:4}).ok);    T(db2.open("1") != null); -   +    restartServer(); -   +    T(db2.open("1") != null); -   +    // You can update but without committing immediately, and then ensure    // everything is commited in the last step. -   +    T(db.save({_id:"2",a:2,b:4}).ok);    T(db.open("2") != null);    T(db.ensureFullCommit().ok);    restartServer(); -   +    T(db.open("2") != null); -   +    // However, it's possible even when flushed, that the server crashed between    // the update and the commit, and you don't want to check to make sure    // every doc you updated actually made it to disk. So record the instance @@ -59,37 +59,37 @@ couchTests.delayed_commits = function(debug) {    // after the flush (the instance start time is returned by the flush    // operation). if they are the same, we know everything was updated    // safely. -   +    // First try it with a crash. -   +    var instanceStartTime = db.info().instance_start_time; -   +    T(db.save({_id:"3",a:2,b:4}).ok);    T(db.open("3") != null); -   +    restartServer(); -   +    var commitResult = db.ensureFullCommit();    T(commitResult.ok && commitResult.instance_start_time != instanceStartTime);    // start times don't match, meaning the server lost our change -   +    T(db.open("3") == null); // yup lost it -   +    // retry with no server restart -   +    var instanceStartTime = db.info().instance_start_time; -   +    T(db.save({_id:"4",a:2,b:4}).ok);    T(db.open("4") != null); -   +    var commitResult = db.ensureFullCommit();    T(commitResult.ok && commitResult.instance_start_time == instanceStartTime);    // Successful commit, start times match! -   +    restartServer(); -   +    T(db.open("4") != null); -   +    // Now test that when we exceed the max_dbs_open, pending commits are safely    // written.    T(db.save({_id:"5",foo:"bar"}).ok); @@ -111,5 +111,5 @@ couchTests.delayed_commits = function(debug) {          dbi.deleteDb();        }      }); -   +  }; diff --git a/share/www/script/test/design_docs.js b/share/www/script/test/design_docs.js index b1ff8432..403f4e43 100644 --- a/share/www/script/test/design_docs.js +++ b/share/www/script/test/design_docs.js @@ -74,16 +74,16 @@ function() {      T(db.ensureFullCommit().ok);      restartServer();    }; -     +    // test when language not specified, Javascript is implied    var designDoc2 = {      _id:"_design/test2", -    // language: "javascript",  +    // language: "javascript",      views: {        single_doc: {map: "function(doc) { if (doc._id == \"1\") { emit(1, null) }}"}      }    }; -   +    T(db.save(designDoc2).ok);    T(db.view("test2/single_doc").total_rows == 1); @@ -113,14 +113,14 @@ function() {    T(db.deleteDoc(designDoc).ok);    T(db.open(designDoc._id) == null);    T(db.view("test/no_docs") == null); -   +    T(db.ensureFullCommit().ok);    restartServer();    T(db.open(designDoc._id) == null);    T(db.view("test/no_docs") == null); -   +    // trigger ddoc cleanup    T(db.viewCleanup().ok); -   +  });  }; diff --git a/share/www/script/test/design_options.js b/share/www/script/test/design_options.js index 4d7684c6..952ecc74 100644 --- a/share/www/script/test/design_options.js +++ b/share/www/script/test/design_options.js @@ -26,7 +26,7 @@ couchTests.design_options = function(debug) {      language: "javascript",      options: {        include_design: true, -      local_seq: true         +      local_seq: true      },      views: {        data: {"map": map}, @@ -63,7 +63,7 @@ couchTests.design_options = function(debug) {    T(db.save(designDoc).ok);    rows = db.view("bango/data").rows;    T(rows.length == 0); -   +    // should also have local_seq in the view    var resp = db.save({});    rows = db.view("fu/with_seq").rows; diff --git a/share/www/script/test/design_paths.js b/share/www/script/test/design_paths.js index 7722a188..df47fbf2 100644 --- a/share/www/script/test/design_paths.js +++ b/share/www/script/test/design_paths.js @@ -18,7 +18,7 @@ couchTests.design_paths = function(debug) {      var dbName = encodeURIComponent(dbNames[i]);      db.deleteDb();      db.createDb(); -     +      // create a ddoc w bulk_docs      db.bulkSave([{        _id : "_design/test", diff --git a/share/www/script/test/etags_views.js b/share/www/script/test/etags_views.js index 018bdc25..1356cdb5 100644 --- a/share/www/script/test/etags_views.js +++ b/share/www/script/test/etags_views.js @@ -15,7 +15,7 @@ couchTests.etags_views = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    var designDoc = {      _id:"_design/etags",      language: "javascript", @@ -43,7 +43,7 @@ couchTests.etags_views = function(debug) {    var xhr;    var docs = makeDocs(0, 10);    db.bulkSave(docs); -   +    // verify get w/Etag on map view    xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/basicView");    T(xhr.status == 200); @@ -53,7 +53,7 @@ couchTests.etags_views = function(debug) {    });    T(xhr.status == 304);    // TODO GET with keys (when that is available) -   +    // reduce view    xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/withReduce");    T(xhr.status == 200); @@ -62,7 +62,7 @@ couchTests.etags_views = function(debug) {      headers: {"if-none-match": etag}    });    T(xhr.status == 304); -   +    // all docs    xhr = CouchDB.request("GET", "/test_suite_db/_all_docs");    T(xhr.status == 200); @@ -79,7 +79,7 @@ couchTests.etags_views = function(debug) {    xhr = CouchDB.request("GET", "/test_suite_db/_all_docs_by_seq", {      headers: {"if-none-match": etag}    }); -  T(xhr.status == 304);     +  T(xhr.status == 304);    // list etag    // in the list test for now diff --git a/share/www/script/test/invalid_docids.js b/share/www/script/test/invalid_docids.js index 4fc4bbf5..a9de0e83 100644 --- a/share/www/script/test/invalid_docids.js +++ b/share/www/script/test/invalid_docids.js @@ -19,7 +19,7 @@ couchTests.invalid_docids = function(debug) {    // Test _local explicitly first.    T(db.save({"_id": "_local/foo"}).ok);    T(db.open("_local/foo")._id == "_local/foo"); -   +    //Test non-string    try {      db.save({"_id": 1}); diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js index bbe0814c..f9268479 100644 --- a/share/www/script/test/list_views.js +++ b/share/www/script/test/list_views.js @@ -15,7 +15,7 @@ couchTests.list_views = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -       +    var designDoc = {      _id:"_design/lists",      language: "javascript", @@ -44,12 +44,12 @@ couchTests.list_views = function(debug) {          var row;          while(row = getRow()) {            log("row: "+toJSON(row)); -          send(row.key);         +          send(row.key);          };          return "tail";        }),        basicJSON : stringFun(function(head, req) { -        start({"headers":{"Content-Type" : "application/json"}});  +        start({"headers":{"Content-Type" : "application/json"}});          send('{"head":'+toJSON(head)+', ');          send('"req":'+toJSON(req)+', ');          send('"rows":['); @@ -144,7 +144,7 @@ couchTests.list_views = function(debug) {          send("head");          var row;          while(row = getRow()) { -          send(row.key);         +          send(row.key);          };          getRow();          getRow(); @@ -165,13 +165,13 @@ couchTests.list_views = function(debug) {    };    T(db.save(designDoc).ok); -   +    var docs = makeDocs(0, 10);    db.bulkSave(docs); -   +    var view = db.view('lists/basicView');    T(view.total_rows == 10); -   +    // standard get    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/basicBasic/basicView");    T(xhr.status == 200, "standard get should be 200"); @@ -214,7 +214,7 @@ couchTests.list_views = function(debug) {    T(!(/Key: 1/.test(xhr.responseText)));    T(/FirstKey: 3/.test(xhr.responseText));    T(/LastKey: 9/.test(xhr.responseText)); -   +    // with 0 rows    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView?startkey=30");    T(xhr.status == 200, "0 rows"); @@ -231,19 +231,19 @@ couchTests.list_views = function(debug) {    T(xhr.status == 200, "reduce 0 rows");    T(/Total Rows/.test(xhr.responseText));    T(/LastKey: undefined/.test(xhr.responseText)); -   +    // when there is a reduce present, but not used    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?reduce=false");    T(xhr.status == 200, "reduce false");    T(/Total Rows/.test(xhr.responseText));    T(/Key: 1/.test(xhr.responseText)); -   +    // when there is a reduce present, and used    xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true");    T(xhr.status == 200, "group reduce");    T(/Key: 1/.test(xhr.responseText)); -   +    // there should be etags on reduce as well    var etag = xhr.getResponseHeader("etag");    T(etag, "Etags should be served with reduce lists"); @@ -251,11 +251,11 @@ couchTests.list_views = function(debug) {      headers: {"if-none-match": etag}    });    T(xhr.status == 304); -   +    // verify the etags expire correctly    var docs = makeDocs(11, 12);    db.bulkSave(docs); -   +    xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true", {      headers: {"if-none-match": etag}    }); @@ -284,7 +284,7 @@ couchTests.list_views = function(debug) {    });    T(xhr.status == 400);    T(/query_parse_error/.test(xhr.responseText)); -     +    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/rowError/basicView");    T(/ReferenceError/.test(xhr.responseText)); @@ -292,7 +292,7 @@ couchTests.list_views = function(debug) {    // now with extra qs params    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/qsParams/basicView?foo=blam");    T(xhr.responseText.match(/blam/)); -   +    var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/basicView");    // T(xhr.getResponseHeader("Content-Type") == "text/plain");    T(xhr.responseText.match(/^head 0 1 2 tail$/) && "basic stop"); @@ -305,7 +305,7 @@ couchTests.list_views = function(debug) {    T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop");    xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/withReduce?group=true");    T(xhr.responseText.match(/^head 0 1 2 tail$/) && "reduce stop 2"); -   +    // with accept headers for HTML    xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/acceptSwitch/basicView", {      headers: { diff --git a/share/www/script/test/purge.js b/share/www/script/test/purge.js index 0b47c0d0..0951bb7a 100644 --- a/share/www/script/test/purge.js +++ b/share/www/script/test/purge.js @@ -15,7 +15,7 @@ couchTests.purge = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    /*     purge is not to be confused with a document deletion.  It removes the     document and all edit history from the local instance of the database. @@ -31,7 +31,7 @@ couchTests.purge = function(debug) {        single_doc: {map: "function(doc) { if (doc._id == \"1\") { emit(1, null) }}"}      }    } -   +    T(db.save(designDoc).ok);    db.bulkSave(makeDocs(1, numDocs + 1)); @@ -43,11 +43,11 @@ couchTests.purge = function(debug) {      T(rows[(2*i)+1].key == i+1);    }    T(db.view("test/single_doc").total_rows == 1); -   +    var info = db.info();    var doc1 = db.open("1");    var doc2 = db.open("2"); -   +    // purge the documents    var xhr = CouchDB.request("POST", "/test_suite_db/_purge", {      body: JSON.stringify({"1":[doc1._rev], "2":[doc2._rev]}), @@ -63,35 +63,35 @@ couchTests.purge = function(debug) {    var result = JSON.parse(xhr.responseText);    T(result.purged["1"][0] == doc1._rev);    T(result.purged["2"][0] == doc2._rev); -   +    T(db.open("1") == null);    T(db.open("2") == null); -   +    var rows = db.view("test/all_docs_twice").rows;    for (var i = 2; i < numDocs; i++) {      T(rows[2*(i-2)].key == i+1);      T(rows[(2*(i-2))+1].key == i+1);    }    T(db.view("test/single_doc").total_rows == 0); -   +    // purge documents twice in a row without loading views    // (causes full view rebuilds) -   +    var doc3 = db.open("3");    var doc4 = db.open("4"); -   +    xhr = CouchDB.request("POST", "/test_suite_db/_purge", {      body: JSON.stringify({"3":[doc3._rev]}),    }); -   +    T(xhr.status == 200); -   +    xhr = CouchDB.request("POST", "/test_suite_db/_purge", {      body: JSON.stringify({"4":[doc4._rev]}),    }); -   +    T(xhr.status == 200); -   +    var rows = db.view("test/all_docs_twice").rows;    for (var i = 4; i < numDocs; i++) {      T(rows[2*(i-4)].key == i+1); diff --git a/share/www/script/test/reduce.js b/share/www/script/test/reduce.js index c8bdcd92..84230998 100644 --- a/share/www/script/test/reduce.js +++ b/share/www/script/test/reduce.js @@ -159,11 +159,11 @@ couchTests.reduce = function(debug) {      docs.push({val:100});      db.bulkSave(docs);    } -   +    var results = db.query(map, reduceCombine); -   +    var difference = results.rows[0].value.stdDeviation - 28.722813232690143;    // account for floating point rounding error    T(Math.abs(difference) < 0.0000000001); -   +  }; diff --git a/share/www/script/test/reduce_builtin.js b/share/www/script/test/reduce_builtin.js index c3d00339..3dc26862 100644 --- a/share/www/script/test/reduce_builtin.js +++ b/share/www/script/test/reduce_builtin.js @@ -15,11 +15,11 @@ couchTests.reduce_builtin = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    var numDocs = 500    var docs = makeDocs(1,numDocs + 1);    db.bulkSave(docs); -   +    var summate = function(N) {return (N+1)*N/2;};    // this is the same test as the reduce.js test @@ -42,7 +42,7 @@ couchTests.reduce_builtin = function(debug) {    T(result.rows[0].value == 18);    result = db.query(map, "_count", {startkey: 4, endkey: 5});    T(result.rows[0].value == 4); -   +    result = db.query(map, "_sum", {startkey: 4, endkey: 6});    T(result.rows[0].value == 30);    result = db.query(map, "_count", {startkey: 4, endkey: 6}); @@ -57,7 +57,7 @@ couchTests.reduce_builtin = function(debug) {      result = db.query(map, "_sum", {startkey: i, endkey: numDocs - i});      T(result.rows[0].value == 2*(summate(numDocs-i) - summate(i-1)));    } -   +    db.deleteDb();    db.createDb(); @@ -88,7 +88,7 @@ couchTests.reduce_builtin = function(debug) {      for (var b=0; b < builtins.length; b++) {        var fun = builtins[b];        var results = db.query(map, fun, {group:true}); -       +        //group by exact key match        T(equals(results.rows[0], {key:["a"],value:20*i}));        T(equals(results.rows[1], {key:["a","b"],value:20*i})); @@ -114,6 +114,6 @@ couchTests.reduce_builtin = function(debug) {        T(equals(results.rows[4], {key:["d","a"],value:10*i}));        T(equals(results.rows[5], {key:["d","b"],value:10*i}));        T(equals(results.rows[6], {key:["d","c"],value:10*i})); -    };     +    };    }  }
\ No newline at end of file diff --git a/share/www/script/test/reduce_false.js b/share/www/script/test/reduce_false.js index 22ef2e8b..e4928cc4 100644 --- a/share/www/script/test/reduce_false.js +++ b/share/www/script/test/reduce_false.js @@ -34,7 +34,7 @@ couchTests.reduce_false = function(debug) {    // Test that the reduce works    var res = db.view('test/summate');    T(res.rows.length == 1 && res.rows[0].value == summate(5)); -   +    //Test that we get our docs back    res = db.view('test/summate', {reduce: false});    T(res.rows.length == 5); diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index 405b0b1d..c9caa5ee 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -35,7 +35,7 @@ couchTests.replication = function(debug) {      dbA.createDb();      dbB.deleteDb();      dbB.createDb(); -     +      var repTests = {        // copy and paste and put your code in. delete unused steps.        test_template: new function () { @@ -49,20 +49,20 @@ couchTests.replication = function(debug) {            // called after replicating src=B  tgt=A first time.          };          this.afterAB2 = function(dbA, dbB) { -          // called after replicating src=A  tgt=B second time.  +          // called after replicating src=A  tgt=B second time.          };          this.afterBA2 = function(dbA, dbB) {            // etc...          };        }, -       +        simple_test: new function () {          this.init = function(dbA, dbB) {            var docs = makeDocs(0, numDocs);            dbA.bulkSave(docs);          }; -       -        this.afterAB1 = function(dbA, dbB) {           + +        this.afterAB1 = function(dbA, dbB) {            for (var j = 0; j < numDocs; j++) {              var docA = dbA.open("" + j);              var docB = dbB.open("" + j); @@ -70,13 +70,13 @@ couchTests.replication = function(debug) {            }          };        }, -     +       deletes_test: new function () {          // make sure deletes are replicated          this.init = function(dbA, dbB) {            T(dbA.save({_id:"foo1",value:"a"}).ok);          }; -         +          this.afterAB1 = function(dbA, dbB) {            var docA = dbA.open("foo1");            var docB = dbB.open("foo1"); @@ -84,13 +84,13 @@ couchTests.replication = function(debug) {            dbA.deleteDoc(docA);          }; -         +          this.afterAB2 = function(dbA, dbB) {            T(dbA.open("foo1") == null);            T(dbB.open("foo1") == null);          };        }, -       +        deleted_test : new function() {          // docs created and deleted on a single node are also replicated          this.init = function(dbA, dbB) { @@ -98,7 +98,7 @@ couchTests.replication = function(debug) {            var docA = dbA.open("del1");            dbA.deleteDoc(docA);          }; -         +          this.afterAB1 = function(dbA, dbB) {            var rows = dbB.allDocsBySeq().rows;            var rowCnt = 0; @@ -111,13 +111,13 @@ couchTests.replication = function(debug) {            T(rowCnt == 1);          };        }, -       +        slashes_in_ids_test: new function () {          // make sure docs with slashes in id replicate properly          this.init = function(dbA, dbB) {            dbA.save({ _id:"abc/def", val:"one" });          }; -         +          this.afterAB1 = function(dbA, dbB) {            var docA = dbA.open("abc/def");            var docB = dbB.open("abc/def"); @@ -137,7 +137,7 @@ couchTests.replication = function(debug) {            T(docA._rev == docB._rev);          };        }, -     +        attachments_test: new function () {          // Test attachments          this.init = function(dbA, dbB) { @@ -161,34 +161,34 @@ couchTests.replication = function(debug) {              }            });          }; -         +          this.afterAB1 = function(dbA, dbB) { -          var xhr = CouchDB.request("GET",  +          var xhr = CouchDB.request("GET",              "/test_suite_db_a/bin_doc/foo%2Bbar.txt");            T(xhr.responseText == "This is a base64 encoded text") -          xhr = CouchDB.request("GET",  +          xhr = CouchDB.request("GET",              "/test_suite_db_b/bin_doc/foo%2Bbar.txt");            T(xhr.responseText == "This is a base64 encoded text")            // and the design-doc -          xhr = CouchDB.request("GET",  +          xhr = CouchDB.request("GET",              "/test_suite_db_a/_design/with_bin/foo%2Bbar.txt");            T(xhr.responseText == "This is a base64 encoded text") -          xhr = CouchDB.request("GET",  +          xhr = CouchDB.request("GET",              "/test_suite_db_b/_design/with_bin/foo%2Bbar.txt");            T(xhr.responseText == "This is a base64 encoded text")          };        }, -       +        conflicts_test: new function () {          // test conflicts          this.init = function(dbA, dbB) {            dbA.save({_id:"foo",value:"a"});            dbB.save({_id:"foo",value:"b"});          }; -         +          this.afterBA1 = function(dbA, dbB) {            var docA = dbA.open("foo", {conflicts: true});            var docB = dbB.open("foo", {conflicts: true}); @@ -202,7 +202,7 @@ couchTests.replication = function(debug) {            // delete a conflict.            dbA.deleteDoc({_id:"foo", _rev:docA._conflicts[0]});          }; -         +          this.afterBA2 = function(dbA, dbB) {            // open documents and include the conflict meta data            var docA = dbA.open("foo", {conflicts: true}); @@ -223,7 +223,7 @@ couchTests.replication = function(debug) {      }      var result = CouchDB.replicate(A, B); -     +      var seqA = result.source_last_seq;      T(0 == result.history[0].start_last_seq);      T(result.history[1] === undefined) @@ -233,7 +233,7 @@ couchTests.replication = function(debug) {      }      result = CouchDB.replicate(B, A); -     +      var seqB = result.source_last_seq;      T(0 == result.history[0].start_last_seq);      T(result.history[1] === undefined) @@ -243,14 +243,14 @@ couchTests.replication = function(debug) {      }      var result2 = CouchDB.replicate(A, B); -     +      // each successful replication produces a new session id      T(result2.session_id != result.session_id); -     +      T(seqA < result2.source_last_seq);      T(seqA == result2.history[0].start_last_seq);      T(result2.history[1].end_last_seq == seqA) -     +      seqA = result2.source_last_seq;      for(test in repTests) { @@ -258,17 +258,17 @@ couchTests.replication = function(debug) {      }      result = CouchDB.replicate(B, A) -     +      T(seqB < result.source_last_seq);      T(seqB == result.history[0].start_last_seq);      T(result.history[1].end_last_seq == seqB) -     +      seqB = result.source_last_seq;      for(test in repTests) {        if(repTests[test].afterBA2) repTests[test].afterBA2(dbA, dbB);      } -     +      // do an replication where nothing has changed      result2 = CouchDB.replicate(B, A);      T(result2.no_changes == true); diff --git a/share/www/script/test/rev_stemming.js b/share/www/script/test/rev_stemming.js index 3832b520..6dc94f70 100644 --- a/share/www/script/test/rev_stemming.js +++ b/share/www/script/test/rev_stemming.js @@ -18,11 +18,11 @@ couchTests.rev_stemming = function(debug) {    dbB.deleteDb();    dbB.createDb();    if (debug) debugger; -   +    var newLimit = 5; -   +    T(db.getDbProperty("_revs_limit") == 1000); -   +    var doc = {_id:"foo",foo:0}    for( var i=0; i < newLimit + 1; i++) {      doc.foo++; @@ -30,30 +30,30 @@ couchTests.rev_stemming = function(debug) {    }    var doc0 = db.open("foo", {revs:true});    T(doc0._revisions.ids.length == newLimit + 1); -   +    var docBar = {_id:"bar",foo:0}    for( var i=0; i < newLimit + 1; i++) {      docBar.foo++;      T(db.save(docBar).ok);    }    T(db.open("bar", {revs:true})._revisions.ids.length == newLimit + 1); -   +    T(db.setDbProperty("_revs_limit", newLimit).ok); -   +    for( var i=0; i < newLimit + 1; i++) {      doc.foo++;      T(db.save(doc).ok);    }    doc0 = db.open("foo", {revs:true});    T(doc0._revisions.ids.length == newLimit); -   -   + +    // If you replicate after you make more edits than the limit, you'll    // cause a spurious edit conflict.    CouchDB.replicate("test_suite_db_a", "test_suite_db_b");    var docB1 = dbB.open("foo",{conflicts:true})    T(docB1._conflicts == null); -   +    for( var i=0; i < newLimit - 1; i++) {      doc.foo++;      T(db.save(doc).ok); @@ -69,30 +69,30 @@ couchTests.rev_stemming = function(debug) {      doc.foo++;      T(db.save(doc).ok);    } -   +    CouchDB.replicate("test_suite_db_a", "test_suite_db_b"); -   +    var docB2 = dbB.open("foo",{conflicts:true}); -   +    // we have a conflict, but the previous replicated rev is always the losing    // conflict    T(docB2._conflicts[0] == docB1._rev) -   +    // We having already updated bar before setting the limit, so it's still got    // a long rev history. compact to stem the revs. -   +    T(db.open("bar", {revs:true})._revisions.ids.length == newLimit + 1); -   +    T(db.compact().ok); -   +    // compaction isn't instantaneous, loop until done    while (db.info().compact_running) {}; -   +    // force reload because ETags don't honour compaction    var req = db.request("GET", "/test_suite_db_a/bar?revs=true", {      headers:{"if-none-match":"pommes"}    }); -   +    var finalDoc = JSON.parse(req.responseText);    TEquals(newLimit, finalDoc._revisions.ids.length,      "should return a truncated revision list"); diff --git a/share/www/script/test/security_validation.js b/share/www/script/test/security_validation.js index 1c185c01..05dff613 100644 --- a/share/www/script/test/security_validation.js +++ b/share/www/script/test/security_validation.js @@ -16,7 +16,7 @@ couchTests.security_validation = function(debug) {    // specifically for this testing. It is a WWWW-Authenticate scheme named    // X-Couch-Test-Auth, and the user names and passwords are hard coded    // on the server-side. -  //  +  //    // We could have used Basic authentication, however the XMLHttpRequest    // implementation for Firefox and Safari, and probably other browsers are    // broken (Firefox always prompts the user on 401 failures, Safari gives @@ -45,7 +45,7 @@ couchTests.security_validation = function(debug) {       {section:"httpd",        key: "WWW-Authenticate",        value:  "X-Couch-Test-Auth"}], -   +      function () {        // try saving document usin the wrong credentials        var wrongPasswordDb = new CouchDB("test_suite_db", @@ -60,8 +60,8 @@ couchTests.security_validation = function(debug) {          T(wrongPasswordDb.last_req.status == 401);        } -      // test force_login=true.  -      var resp = wrongPasswordDb.request("GET", "/_whoami?force_login=true");     +      // test force_login=true. +      var resp = wrongPasswordDb.request("GET", "/_whoami?force_login=true");        var err = JSON.parse(resp.responseText);        T(err.error == "unauthorized");        T(resp.status == 401); @@ -110,7 +110,7 @@ couchTests.security_validation = function(debug) {        T(user.name == "Damien Katz");        // test that the roles are listed properly        TEquals(user.roles, []); -       +        // update the document        var doc = userDb.open("testdoc"); @@ -126,7 +126,7 @@ couchTests.security_validation = function(debug) {          T(userDb.last_req.status == 403);        } -      // Now attempt to update the document as a different user, Jan  +      // Now attempt to update the document as a different user, Jan        var user2Db = new CouchDB("test_suite_db",          {"WWW-Authenticate": "X-Couch-Test-Auth Jan Lehnardt:apple"}        ); @@ -161,7 +161,7 @@ couchTests.security_validation = function(debug) {        }        // Now delete document -      T(user2Db.deleteDoc(doc).ok);       +      T(user2Db.deleteDoc(doc).ok);        // now test bulk docs        var docs = [{_id:"bahbah",author:"Damien Katz",foo:"bar"},{_id:"fahfah",foo:"baz"}]; @@ -173,11 +173,11 @@ couchTests.security_validation = function(debug) {        T(results[0].error == undefined)        T(results[1].rev === undefined)        T(results[1].error == "forbidden") -       +        T(db.open("bahbah"));        T(db.open("fahfah") == null); -       -       + +        // now all or nothing with a failure        var docs = [{_id:"booboo",author:"Damien Katz",foo:"bar"},{_id:"foofoo",foo:"baz"}]; @@ -188,23 +188,23 @@ couchTests.security_validation = function(debug) {        T(results.errors[0].error == "forbidden");        T(db.open("booboo") == null);        T(db.open("foofoo") == null); -       -       + +        // Now test replication        var AuthHeaders = {"WWW-Authenticate": "X-Couch-Test-Auth Christopher Lenz:dog food"};        var host = CouchDB.host;        var dbPairs = [          {source:"test_suite_db_a",            target:"test_suite_db_b"}, -     +          {source:"test_suite_db_a",            target:{url: "http://" + host + "/test_suite_db_b",                    headers: AuthHeaders}}, -         +          {source:{url:"http://" + host + "/test_suite_db_a",                   headers: AuthHeaders},            target:"test_suite_db_b"}, -         +          {source:{url:"http://" + host + "/test_suite_db_a",                   headers: AuthHeaders},           target:{url:"http://" + host + "/test_suite_db_b", @@ -225,7 +225,7 @@ couchTests.security_validation = function(debug) {          adminDbA.createDb();          adminDbB.deleteDb();          adminDbB.createDb(); -   +          // save and replicate a documents that will and will not pass our design          // doc validation function.          dbA.save({_id:"foo1",value:"a",author:"Noah Slater"}); @@ -239,44 +239,44 @@ couchTests.security_validation = function(debug) {          T(dbB.open("foo1"));          T(dbA.open("foo2"));          T(dbB.open("foo2")); -   +          // save the design doc to dbA          delete designDoc._rev; // clear rev from previous saves          adminDbA.save(designDoc);          // no affect on already saved docs          T(dbA.open("bad1")); -   +          // Update some docs on dbB. Since the design hasn't replicated, anything          // is allowed. -   +          // this edit will fail validation on replication to dbA (no author)          T(dbB.save({_id:"bad2",value:"a"}).ok); -   +          // this edit will fail security on replication to dbA (wrong author          //  replicating the change)          var foo1 = dbB.open("foo1");          foo1.value = "b";          dbB.save(foo1); -   +          // this is a legal edit          var foo2 = dbB.open("foo2");          foo2.value = "b";          dbB.save(foo2); -   +          var results = CouchDB.replicate(B, A, {headers:AuthHeaders}); -   +          T(results.ok); -   +          T(results.history[0].docs_written == 1);          T(results.history[0].doc_write_failures == 2); -   +          // bad2 should not be on dbA          T(dbA.open("bad2") == null); -   +          // The edit to foo1 should not have replicated.          T(dbA.open("foo1").value == "a"); -   +          // The edit to foo2 should have replicated.          T(dbA.open("foo2").value == "b");        } diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js index 64a6788f..7201ae81 100644 --- a/share/www/script/test/show_documents.js +++ b/share/www/script/test/show_documents.js @@ -16,12 +16,12 @@ couchTests.show_documents = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -       +    var designDoc = {      _id:"_design/template",      language: "javascript",      shows: { -      "hello" : stringFun(function(doc, req) {  +      "hello" : stringFun(function(doc, req) {          if (doc) {            return "Hello World";          } else { @@ -77,7 +77,7 @@ couchTests.show_documents = function(debug) {          if (req.headers["Accept"].match(/image/)) {            return {              // a 16x16 px version of the CouchDB logo -            "base64" :  +            "base64" :  ["iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV",  "BMVEUAAAD////////////////////////5ur3rEBn////////////////wDBL/",  "AADuBAe9EB3IEBz/7+//X1/qBQn2AgP/f3/ilpzsDxfpChDtDhXeCA76AQH/v7", @@ -129,7 +129,7 @@ couchTests.show_documents = function(debug) {      }    };    T(db.save(designDoc).ok); -   +    var doc = {"word":"plankton", "name":"Rusty"}    var resp = db.save(doc);    T(resp.ok); @@ -139,7 +139,7 @@ couchTests.show_documents = function(debug) {    var xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/");    T(xhr.status == 404, 'Should be missing');    T(JSON.parse(xhr.responseText).reason == "Invalid path."); -   +    // hello template world    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/"+docid);    T(xhr.responseText == "Hello World"); @@ -151,7 +151,7 @@ couchTests.show_documents = function(debug) {    // // error stacktraces    // xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/render-error/"+docid);    // T(JSON.parse(xhr.responseText).error == "render_error"); -  +    // hello template world (no docid)    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello");    T(xhr.responseText == "Empty World"); @@ -159,21 +159,21 @@ couchTests.show_documents = function(debug) {    // // hello template world (non-existing docid)    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc");    T(xhr.responseText == "New World"); -   +    // show with doc    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/"+docid);    T(xhr.responseText == "Just Rusty"); -   +    // show with missing doc    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/missingdoc");    T(xhr.status == 404, 'Doc should be missing');    T(xhr.responseText == "No such doc"); -   +    // show with missing func    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/missing/"+docid);    T(xhr.status == 404, "function is missing"); -   +    // missing design doc    xhr = CouchDB.request("GET", "/test_suite_db/_design/missingddoc/_show/just-name/"+docid);    T(xhr.status == 404); @@ -200,7 +200,7 @@ couchTests.show_documents = function(debug) {    T("Accept" == xhr.getResponseHeader("Vary"));    // accept header switching -  // different mime has different etag   +  // different mime has different etag    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/accept-switch/"+docid, {      headers: {"Accept": "text/html;text/plain;*/*"}    }); @@ -227,7 +227,7 @@ couchTests.show_documents = function(debug) {      headers: {"if-none-match": etag}    });    // should be 304 -  T(xhr.status == 304);     +  T(xhr.status == 304);    // update the doc    doc.name = "Crusty"; @@ -237,7 +237,7 @@ couchTests.show_documents = function(debug) {    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/"+docid, {      headers: {"if-none-match": etag}    }); -  // status is 200     +  // status is 200    T(xhr.status == 200);    // get new etag and request again @@ -251,7 +251,7 @@ couchTests.show_documents = function(debug) {    // update design doc (but not function)    designDoc.isChanged = true;    T(db.save(designDoc).ok); -   +    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/"+docid, {      headers: {"if-none-match": etag}    }); @@ -269,7 +269,7 @@ couchTests.show_documents = function(debug) {    xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/just-name/"+docid, {      headers: {"if-none-match": etag}    }); -  // status is 200     +  // status is 200    T(xhr.status == 200); @@ -287,7 +287,7 @@ couchTests.show_documents = function(debug) {    });    var ct = xhr.getResponseHeader("Content-Type");    T(/charset=utf-8/.test(ct)) -  T(/text\/html/.test(ct))   +  T(/text\/html/.test(ct))    T(xhr.responseText == "Ha ha, you said \"plankton\".");    // now with xml diff --git a/share/www/script/test/stats.js b/share/www/script/test/stats.js index 8a21dd88..7c9b5da3 100644 --- a/share/www/script/test/stats.js +++ b/share/www/script/test/stats.js @@ -76,7 +76,7 @@ couchTests.stats = function(debug) {          })      },   }; -   +    var request_count_tests = {     'should increase the request count for every request': function(name) {       var requests = requestStatsTest("httpd", "requests").current + 1; @@ -88,7 +88,7 @@ couchTests.stats = function(debug) {       TEquals(requests + 1, new_requests, name);     }   }; -  +   var database_read_count_tests = {     'should increase database reads counter when a document is read': function(name) {       var db = new CouchDB("test_suite_db"); @@ -186,7 +186,7 @@ couchTests.stats = function(debug) {       TEquals(reads + 1 , new_reads, name);     }   }; -  +   var http_requests_by_method_tests = {     'should count GET requests': function(name) {       var requests = requestStatsTest("httpd_request_methods", "GET").current; @@ -199,7 +199,7 @@ couchTests.stats = function(debug) {       CouchDB.request("POST", "/");       var new_requests = requestStatsTest("httpd_request_methods", "GET").current; -     TEquals(requests + 1, new_requests, name);         +     TEquals(requests + 1, new_requests, name);     },     'should count POST requests': function(name) {       var requests = requestStatsTest("httpd_request_methods", "POST").current; @@ -229,7 +229,7 @@ couchTests.stats = function(debug) {       var doc = {"_id":"test"};       db.save(doc); -      +       var updates = requestStatsTest("couchdb", "database_writes").current;       db.save(doc);       var new_updates = requestStatsTest("couchdb", "database_writes").current; @@ -243,7 +243,7 @@ couchTests.stats = function(debug) {       var doc = {"_id":"test"};       db.save(doc); -      +       var deletes = requestStatsTest("couchdb", "database_writes").current;       db.deleteDoc(doc);       var new_deletes = requestStatsTest("couchdb", "database_writes").current; @@ -275,7 +275,7 @@ couchTests.stats = function(debug) {       var docs = makeDocs(5);       db.bulkSave(docs); -      +       var new_bulks = requestStatsTest("httpd", "bulk_requests").current;       TEquals(bulks + 1, new_bulks, name); @@ -378,7 +378,7 @@ couchTests.stats = function(debug) {       var options = {};       options.headers = {"Accept": "application/json"};       var summary = JSON.parse(CouchDB.request("GET", "/_stats", options).responseText); -     var aggregates = ["mean", "min", "max", "stddev",  +     var aggregates = ["mean", "min", "max", "stddev",         "current"];       for(var i in aggregates) { @@ -386,12 +386,12 @@ couchTests.stats = function(debug) {       }     }   }; -  +     var tests = [       open_databases_tests, -     request_count_tests,  -     database_read_count_tests,  -     view_read_count_tests,  +     request_count_tests, +     database_read_count_tests, +     view_read_count_tests,       http_requests_by_method_tests,       document_write_count_tests,       response_codes_tests, @@ -404,7 +404,7 @@ couchTests.stats = function(debug) {         tests[testGroup][test](test);       }     }; -  +     function createAndRequestView(db) {       var designDoc = {         _id:"_design/test", // turn off couch.js id escaping? @@ -414,7 +414,7 @@ couchTests.stats = function(debug) {         }       };       db.save(designDoc); -  +       db.view("test/all_docs_twice");     } @@ -422,4 +422,3 @@ couchTests.stats = function(debug) {       return CouchDB.requestStats(module, key, true);     }  } - 
\ No newline at end of file diff --git a/share/www/script/test/uuids.js b/share/www/script/test/uuids.js index 6f701884..f4b95898 100644 --- a/share/www/script/test/uuids.js +++ b/share/www/script/test/uuids.js @@ -14,20 +14,20 @@ couchTests.uuids = function(debug) {    var testHashBustingHeaders = function(xhr) {      T(xhr.getResponseHeader("Cache-Control").match(/no-cache/));      T(xhr.getResponseHeader("Pragma") == "no-cache"); -     +      var currentTime = new Date();      var expiresHeader = Date.parse(xhr.getResponseHeader("Expires")); -    var dateHeader = Date.parse(xhr.getResponseHeader("Date"));  -     +    var dateHeader = Date.parse(xhr.getResponseHeader("Date")); +      T(expiresHeader < currentTime);      T(currentTime - dateHeader < 3000);    }; -     +    var db = new CouchDB("test_suite_db");    db.deleteDb();    db.createDb();    if (debug) debugger; -   +    // a single UUID without an explicit count    var xhr = CouchDB.request("GET", "/_uuids");    T(xhr.status == 200); @@ -55,7 +55,7 @@ couchTests.uuids = function(debug) {      T(seen[id] === undefined);      seen[id] = 1;    } -   +    // ensure we return a 405 on POST    xhr = CouchDB.request("POST", "/_uuids?count=1000");    T(xhr.status == 405); diff --git a/share/www/script/test/view_collation.js b/share/www/script/test/view_collation.js index f59204c7..09681cc9 100644 --- a/share/www/script/test/view_collation.js +++ b/share/www/script/test/view_collation.js @@ -85,14 +85,14 @@ couchTests.view_collation = function(debug) {      rows = db.query(queryFun, null, queryOptions).rows;      T(rows.length == 1 && equals(rows[0].key, values[i]));    } -   +    // test inclusive_end=true (the default)    // the inclusive_end=true functionality is limited to endkey currently    // if you need inclusive_start=false for startkey, please do implement. ;)    var rows = db.query(queryFun, null, {endkey : "b", inclusive_end:true}).rows;    T(rows[rows.length-1].key == "b")    // descending=true -  var rows = db.query(queryFun, null, {endkey : "b",  +  var rows = db.query(queryFun, null, {endkey : "b",      descending:true, inclusive_end:true}).rows;    T(rows[rows.length-1].key == "b") @@ -100,13 +100,13 @@ couchTests.view_collation = function(debug) {    var rows = db.query(queryFun, null, {endkey : "b", inclusive_end:false}).rows;    T(rows[rows.length-1].key == "aa")    // descending=true -  var rows = db.query(queryFun, null, {endkey : "b",  +  var rows = db.query(queryFun, null, {endkey : "b",      descending:true, inclusive_end:false}).rows;    T(rows[rows.length-1].key == "B") -   +    // inclusive_end=false overrides endkey_docid    var rows = db.query(queryFun, null, { -    endkey : "b", endkey_docid: "b",  +    endkey : "b", endkey_docid: "b",      inclusive_end:false}).rows;    T(rows[rows.length-1].key == "aa")  }; diff --git a/share/www/script/test/view_errors.js b/share/www/script/test/view_errors.js index c9ef6d0c..545115cf 100644 --- a/share/www/script/test/view_errors.js +++ b/share/www/script/test/view_errors.js @@ -15,14 +15,14 @@ couchTests.view_errors = function(debug) {    db.deleteDb();    db.createDb();    if (debug) debugger; -   -   + +    run_on_modified_server(      [{section: "couchdb",        key: "os_process_timeout",        value: "500"}], -    function() {     +    function() {        var doc = {integer: 1, string: "1", array: [1, 2, 3]};        T(db.save(doc).ok); @@ -47,37 +47,37 @@ couchTests.view_errors = function(debug) {          emit([doc._id, doc.undef], null);        });        T(results.total_rows == 0); -   +        // querying a view with invalid params should give a resonable error message        var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view?startkey=foo", {          headers: {"Content-Type": "application/json"}, -        body: JSON.stringify({language: "javascript",  +        body: JSON.stringify({language: "javascript",            map : "function(doc){emit(doc.integer)}"          })        });        T(JSON.parse(xhr.responseText).error == "invalid_json"); -   +        // views should ignore Content-Type, like the rest of CouchDB        var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view", {          headers: {"Content-Type": "application/x-www-form-urlencoded"}, -        body: JSON.stringify({language: "javascript",  +        body: JSON.stringify({language: "javascript",            map : "function(doc){}"          })        });        T(xhr.status == 200); -   +        var map = function (doc) {emit(doc.integer, doc.integer);}; -   +        try {            db.query(map, null, {group: true});            T(0 == 1);        } catch(e) {            T(e.error == "query_parse_error");        } -   +        // reduce=false on map views doesn't work, so group=true will        // never throw for temp reduce views. -   +        var designDoc = {          _id:"_design/test",          language: "javascript", @@ -89,7 +89,7 @@ couchTests.view_errors = function(debug) {          }        };        T(db.save(designDoc).ok); -   +        var designDoc2 = {          _id:"_design/testbig",          language: "javascript", @@ -100,14 +100,14 @@ couchTests.view_errors = function(debug) {          }        };        T(db.save(designDoc2).ok); -   +        try {            db.view("test/no_reduce", {group: true});            T(0 == 1);        } catch(e) {            T(e.error == "query_parse_error");        } -   +        try {          db.view("test/no_reduce", {reduce: true});          T(0 == 1); @@ -122,7 +122,7 @@ couchTests.view_errors = function(debug) {        } catch(e) {            T(e.error == "query_parse_error");        } -   +        var designDoc3 = {          _id:"_design/infinite",          language: "javascript", @@ -138,7 +138,7 @@ couchTests.view_errors = function(debug) {        } catch(e) {            T(e.error == "os_process_error");        } -     +        // Check error responses for invalid multi-get bodies.        var path = "/test_suite_db/_design/test/_view/no_reduce";        var xhr = CouchDB.request("POST", path, {body: "[]"}); diff --git a/share/www/script/test/view_multi_key_design.js b/share/www/script/test/view_multi_key_design.js index c2833910..d0ba7374 100644 --- a/share/www/script/test/view_multi_key_design.js +++ b/share/www/script/test/view_multi_key_design.js @@ -53,7 +53,7 @@ couchTests.view_multi_key_design = function(debug) {      T(keys.indexOf(rows[i].key) != -1);      T(rows[i].key == rows[i].value);    } -   +    var reduce = db.view("test/summate",{group:true},keys).rows;    T(reduce.length == keys.length);    for(var i=0; i<reduce.length; i++) { diff --git a/share/www/script/test/view_multi_key_temp.js b/share/www/script/test/view_multi_key_temp.js index 545e2520..0e42ce67 100644 --- a/share/www/script/test/view_multi_key_temp.js +++ b/share/www/script/test/view_multi_key_temp.js @@ -28,7 +28,7 @@ couchTests.view_multi_key_temp = function(debug) {      T(keys.indexOf(rows[i].key) != -1);      T(rows[i].key == rows[i].value);    } -   +    var reduce = db.query(queryFun, reduceFun, {group:true}, keys).rows;    for(var i=0; i<reduce.length; i++) {      T(keys.indexOf(reduce[i].key) != -1); diff --git a/share/www/script/test/view_offsets.js b/share/www/script/test/view_offsets.js index e32d070b..31dee8e9 100644 --- a/share/www/script/test/view_offsets.js +++ b/share/www/script/test/view_offsets.js @@ -11,12 +11,12 @@  // the License.  couchTests.view_offsets = function(debug) { -  if (debug) debugger;       +  if (debug) debugger;    var db = new CouchDB("test_suite_db");    db.deleteDb();    db.createDb(); -   +    var designDoc = {      _id : "_design/test",      views : { @@ -26,7 +26,7 @@ couchTests.view_offsets = function(debug) {      }    };    T(db.save(designDoc).ok); -   +    var docs = [      {_id : "a1", letter : "a", number : 1, foo: "bar"},      {_id : "a2", letter : "a", number : 2, foo: "bar"}, @@ -88,8 +88,8 @@ couchTests.view_offsets = function(debug) {      ];      db.bulkSave(docs); -    var res = db.view("test/offset", {  -      startkey: ["b",4], startkey_docid: "b4", endkey: ["b"],  +    var res = db.view("test/offset", { +      startkey: ["b",4], startkey_docid: "b4", endkey: ["b"],        limit: 2, descending: true, skip: 1      }) diff --git a/share/www/script/test/view_pagination.js b/share/www/script/test/view_pagination.js index 21eab888..f6154d36 100644 --- a/share/www/script/test/view_pagination.js +++ b/share/www/script/test/view_pagination.js @@ -71,7 +71,7 @@ couchTests.view_pagination = function(debug) {          T(queryResults.rows[j].key == i + j);        }      } -     +      // test endkey_docid      var queryResults = db.query(function(doc) { emit(null, null);}, null, {        startkey: null, @@ -79,7 +79,7 @@ couchTests.view_pagination = function(debug) {        endkey: null,        endkey_docid: 40      }); -     +      T(queryResults.rows.length == 35)      T(queryResults.total_rows == docs.length)      T(queryResults.offset == 1) | 
