diff options
author | Randall Leeds <randall@apache.org> | 2011-12-14 22:52:13 -0800 |
---|---|---|
committer | Randall Leeds <randall@apache.org> | 2012-01-26 17:03:10 -0800 |
commit | 127cbe36c279ee46f387143a74613ba546e06e42 (patch) | |
tree | 1a24454c490c5aedd0dbdd3577e4dd6dfea2d22f | |
parent | d20e792617db738dd5ad0e046ae847cd740f586f (diff) | |
download | couchdb-127cbe36c279ee46f387143a74613ba546e06e42.tar.gz |
Fix JS tests for COUCHDB-1338
Fix two bad assumptions:
- The server restarts on the same port
Change replicator_db test which verifies that replications described
by _replicator documents survive restart to use non-HTTP db references.
- The config port matches the port in the CouchDB request URL.
-rw-r--r-- | share/www/script/couch.js | 13 | ||||
-rw-r--r-- | share/www/script/test/config.js | 2 | ||||
-rw-r--r-- | share/www/script/test/replicator_db.js | 39 |
3 files changed, 32 insertions, 22 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js index d078d9647..f7099e3f0 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -478,7 +478,18 @@ CouchDB.params = function(options) { }; // Used by replication test if (typeof window == 'undefined' || !window) { - CouchDB.host = "127.0.0.1:5984"; + var hostRE = RegExp("https?://([^\/]+)"); + var getter = function () { + return (new CouchHTTP).base_url.match(hostRE)[1]; + }; + if(Object.defineProperty) { + Object.defineProperty(CouchDB, "host", { + get : getter, + enumerable : true + }); + } else { + CouchDB.__defineGetter__("host", getter); + } CouchDB.protocol = "http://"; CouchDB.inBrowser = false; } else { diff --git a/share/www/script/test/config.js b/share/www/script/test/config.js index 9e4ae3587..5382778f6 100644 --- a/share/www/script/test/config.js +++ b/share/www/script/test/config.js @@ -46,7 +46,7 @@ couchTests.config = function(debug) { config_port = config.ssl.port; } - if(port) { + if(port && config_port != "0") { TEquals(config_port, port, "ports should match"); } diff --git a/share/www/script/test/replicator_db.js b/share/www/script/test/replicator_db.js index 5eedc106b..379538685 100644 --- a/share/www/script/test/replicator_db.js +++ b/share/www/script/test/replicator_db.js @@ -15,7 +15,6 @@ couchTests.replicator_db = function(debug) { if (debug) debugger; var wait_rep_doc = 500; // number of millisecs to wait after saving a Rep Doc - var host = CouchDB.host; var dbA = new CouchDB("test_suite_rep_db_a", {"X-Couch-Full-Commit":"false"}); var dbB = new CouchDB("test_suite_rep_db_b", {"X-Couch-Full-Commit":"false"}); var repDb = new CouchDB("test_suite_rep_db", {"X-Couch-Full-Commit":"false"}); @@ -157,7 +156,7 @@ couchTests.replicator_db = function(debug) { var repDoc = { _id: "foo_filt_rep_doc", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name, filter: "mydesign/myfilter", query_params: { @@ -206,7 +205,7 @@ couchTests.replicator_db = function(debug) { var repDoc = { _id: "foo_cont_rep_doc", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name, continuous: true, user_ctx: { @@ -305,7 +304,7 @@ couchTests.replicator_db = function(debug) { var repDoc = { _id: "foo_cont_rep_doc", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name, doc_ids: ["foo666", "foo3", "_design/mydesign", "foo999", "foo1"] }; @@ -435,12 +434,12 @@ couchTests.replicator_db = function(debug) { var repDoc1 = { _id: "foo_dup_rep_doc_1", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name }; var repDoc2 = { _id: "foo_dup_rep_doc_2", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name }; @@ -477,13 +476,13 @@ couchTests.replicator_db = function(debug) { var repDoc1 = { _id: "foo_dup_cont_rep_doc_1", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name, continuous: true }; var repDoc2 = { _id: "foo_dup_cont_rep_doc_2", - source: "http://" + host + "/" + dbA.name, + source: "http://" + CouchDB.host + "/" + dbA.name, target: dbB.name, continuous: true }; @@ -663,7 +662,7 @@ couchTests.replicator_db = function(debug) { var repDoc = { _id: "foo_cont_rep_survives_doc", - source: "http://" + host + "/" + dbA.name, + source: dbA.name, target: dbB.name, continuous: true }; @@ -805,7 +804,7 @@ couchTests.replicator_db = function(debug) { var repDoc = { _id: "foo_rep", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbB.name }; @@ -901,7 +900,7 @@ couchTests.replicator_db = function(debug) { repDoc = { _id: "foo_rep_2", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbB.name, user_ctx: { name: "joe", @@ -949,7 +948,7 @@ couchTests.replicator_db = function(debug) { repDoc = { _id: "foo_rep_3", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbB.name }; @@ -968,7 +967,7 @@ couchTests.replicator_db = function(debug) { repDoc = { _id: "foo_rep_4", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbB.name, user_ctx: { roles: ["_admin"] @@ -1043,19 +1042,19 @@ couchTests.replicator_db = function(debug) { repDoc1 = { _id: "rep1", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbA_copy.name, continuous: true }; repDoc2 = { _id: "rep2", - source: CouchDB.protocol + host + "/" + dbB.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbB.name, target: dbB_copy.name, continuous: true }; repDoc3 = { _id: "rep3", - source: CouchDB.protocol + host + "/" + dbC.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbC.name, target: dbC_copy.name, continuous: true }; @@ -1144,13 +1143,13 @@ couchTests.replicator_db = function(debug) { repDoc1 = { _id: "rep1", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbA_copy.name, continuous: true }; repDoc2 = { _id: "rep2", - source: CouchDB.protocol + host + "/" + dbB.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbB.name, target: dbB_copy.name, continuous: true }; @@ -1413,12 +1412,12 @@ couchTests.replicator_db = function(debug) { repDoc1 = { _id: "rep1", - source: CouchDB.protocol + host + "/" + dbA.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbA.name, target: dbA_copy.name }; repDoc2 = { _id: "rep2", - source: CouchDB.protocol + host + "/" + dbB.name, + source: CouchDB.protocol + CouchDB.host + "/" + dbB.name, target: dbB_copy.name }; |