Skip to content

Commit

Permalink
Import the unit tests from geocouch_v1.0.2r1
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs committed Feb 13, 2011
1 parent 9428661 commit 3cc06e4
Show file tree
Hide file tree
Showing 7 changed files with 1,091 additions and 0 deletions.
5 changes: 5 additions & 0 deletions share/Makefile.am
Expand Up @@ -135,18 +135,21 @@ nobase_dist_localdata_DATA = \
www/script/test/design_paths.js \
www/script/test/erlang_views.js \
www/script/test/etags_head.js \
www/script/test/etags_spatial.js \
www/script/test/etags_views.js \
www/script/test/form_submit.js \
www/script/test/http.js \
www/script/test/invalid_docids.js \
www/script/test/jsonp.js \
www/script/test/large_docs.js \
www/script/test/list_spatial.js \
www/script/test/list_views.js \
www/script/test/lorem.txt \
www/script/test/lorem_b64.txt \
www/script/test/lots_of_docs.js \
www/script/test/method_override.js \
www/script/test/multiple_rows.js \
www/script/test/multiple_spatial_rows.js \
www/script/test/oauth.js \
www/script/test/proxyauth.js \
www/script/test/purge.js \
Expand All @@ -161,6 +164,8 @@ nobase_dist_localdata_DATA = \
www/script/test/rewrite.js \
www/script/test/security_validation.js \
www/script/test/show_documents.js \
www/script/test/spatial.js \
www/script/test/spatial_compaction.js \
www/script/test/stats.js \
www/script/test/update_documents.js \
www/script/test/users_db.js \
Expand Down
5 changes: 5 additions & 0 deletions share/www/script/couch_tests.js
Expand Up @@ -52,16 +52,19 @@ loadTest("design_options.js");
loadTest("design_paths.js");
loadTest("erlang_views.js");
loadTest("etags_head.js");
loadTest("etags_spatial.js");
loadTest("etags_views.js");
loadTest("form_submit.js");
loadTest("http.js");
loadTest("invalid_docids.js");
loadTest("jsonp.js");
loadTest("large_docs.js");
loadTest("list_spatial.js");
loadTest("list_views.js");
loadTest("lots_of_docs.js");
loadTest("method_override.js");
loadTest("multiple_rows.js");
loadTest("multiple_spatial_rows.js");
loadScript("script/oauth.js");
loadScript("script/sha1.js");
loadTest("oauth.js");
Expand All @@ -78,6 +81,8 @@ loadTest("rev_stemming.js");
loadTest("rewrite.js");
loadTest("security_validation.js");
loadTest("show_documents.js");
loadTest("spatial.js");
loadTest("spatial_compaction.js");
loadTest("stats.js");
loadTest("update_documents.js");
loadTest("users_db.js");
Expand Down
108 changes: 108 additions & 0 deletions share/www/script/test/etags_spatial.js
@@ -0,0 +1,108 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

couchTests.etags_spatial = function(debug) {
var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"});
db.deleteDb();
db.createDb();
if (debug) debugger;

var designDoc = {
_id:"_design/etags",
language: "javascript",
spatial: {
basicIndex: stringFun(function(doc) {
emit({
type: "Point",
coordinates: [doc.loc[0], doc.loc[1]]
}, doc.string);
}),
fooIndex: stringFun(function(doc) {
if (doc.foo) {
emit({
type: "Point",
coordinates: [1, 2]
}, 1);
}
})
}
};
T(db.save(designDoc).ok);

function makeSpatialDocs(start, end, templateDoc) {
var docs = makeDocs(start, end, templateDoc);
for (var i=0; i<docs.length; i++) {
docs[i].loc = [i-20+docs[i].integer, i+15+docs[i].integer];
}
return docs;
}

var xhr;
var url_pre = '/test_suite_db/_design/etags/_spatial/';
var docs = makeSpatialDocs(0, 10);
db.bulkSave(docs);

var bbox = [-180, -90, 180, 90];
// verify get w/Etag on spatial index
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","));
T(xhr.status == 200);
var etag = xhr.getResponseHeader("etag");
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","), {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);

// verify ETag doesn't change when an update
// doesn't change the view group's index
T(db.save({"_id":"doc1", "foo":"bar"}).ok);
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","));
var etag1 = xhr.getResponseHeader("etag");
T(etag1 == etag);

/*
// NOTE vmx (2011-01-13) purging is not yet implemented for the spatial index
// Verify that purges affect etags
xhr = CouchDB.request("GET", url_pre + "fooIndex?bbox=" + bbox.join(","));
var foo_etag = xhr.getResponseHeader("etag");
var doc1 = db.open("doc1");
xhr = CouchDB.request("POST", "/test_suite_db/_purge", {
body: JSON.stringify({"doc1":[doc1._rev]})
});
xhr = CouchDB.request("GET", url_pre + "fooIndex?bbox=" + bbox.join(","));
etag1 = xhr.getResponseHeader("etag");
T(etag1 != foo_etag);
// Test that _purge didn't affect the other view etags.
xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/basicView");
etag1 = xhr.getResponseHeader("etag");
T(etag1 == etag);
*/

// verify different views in the same view group may have different ETags
xhr = CouchDB.request("GET", url_pre + "fooIndex?bbox=" + bbox.join(","));
etag1 = xhr.getResponseHeader("etag");
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","));
var etag2 = xhr.getResponseHeader("etag");
T(etag1 != etag2);

// verify ETag changes when an update changes the view group's index.
db.bulkSave(makeSpatialDocs(10, 20));
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","));
etag1 = xhr.getResponseHeader("etag");
T(etag1 != etag);

// verify ETag is the same after a restart
restartServer();
xhr = CouchDB.request("GET", url_pre + "basicIndex?bbox=" + bbox.join(","));
etag2 = xhr.getResponseHeader("etag");
T(etag1 == etag2);
};

0 comments on commit 3cc06e4

Please sign in to comment.