summaryrefslogtreecommitdiff
path: root/share/www/script/test/view_errors.js
diff options
context:
space:
mode:
Diffstat (limited to 'share/www/script/test/view_errors.js')
-rw-r--r--share/www/script/test/view_errors.js54
1 files changed, 40 insertions, 14 deletions
diff --git a/share/www/script/test/view_errors.js b/share/www/script/test/view_errors.js
index 0f90c46f..e8bd08e4 100644
--- a/share/www/script/test/view_errors.js
+++ b/share/www/script/test/view_errors.js
@@ -16,8 +16,6 @@ couchTests.view_errors = function(debug) {
db.createDb();
if (debug) debugger;
-
-
run_on_modified_server(
[{section: "couchdb",
key: "os_process_timeout",
@@ -26,12 +24,13 @@ couchTests.view_errors = function(debug) {
var doc = {integer: 1, string: "1", array: [1, 2, 3]};
T(db.save(doc).ok);
- // emitting a key value that is undefined should result in that row not
- // being included in the view results
+ // emitting a key value that is undefined should result in that row
+ // being included in the view results as null
var results = db.query(function(doc) {
emit(doc.undef, null);
});
- T(results.total_rows == 0);
+ T(results.total_rows == 1);
+ T(results.rows[0].key == null);
// if a view function throws an exception, its results are not included in
// the view index, but the view does not itself raise an error
@@ -41,13 +40,13 @@ couchTests.view_errors = function(debug) {
T(results.total_rows == 0);
// if a view function includes an undefined value in the emitted key or
- // value, an error is logged and the result is not included in the view
- // index, and the view itself does not raise an error
+ // value, it is treated as null
var results = db.query(function(doc) {
emit([doc._id, doc.undef], null);
});
- T(results.total_rows == 0);
-
+ T(results.total_rows == 1);
+ T(results.rows[0].key[1] == null);
+
// 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"},
@@ -57,14 +56,14 @@ couchTests.view_errors = function(debug) {
});
T(JSON.parse(xhr.responseText).error == "bad_request");
- // views should ignore Content-Type, like the rest of CouchDB
+ // content type must be json
var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view", {
headers: {"Content-Type": "application/x-www-form-urlencoded"},
body: JSON.stringify({language: "javascript",
map : "function(doc){}"
})
});
- T(xhr.status == 200);
+ T(xhr.status == 415);
var map = function (doc) {emit(doc.integer, doc.integer);};
@@ -75,9 +74,6 @@ couchTests.view_errors = function(debug) {
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",
@@ -105,6 +101,15 @@ couchTests.view_errors = function(debug) {
db.view("test/no_reduce", {group: true});
T(0 == 1);
} catch(e) {
+ T(db.last_req.status == 400);
+ T(e.error == "query_parse_error");
+ }
+
+ try {
+ db.view("test/no_reduce", {group_level: 1});
+ T(0 == 1);
+ } catch(e) {
+ T(db.last_req.status == 400);
T(e.error == "query_parse_error");
}
@@ -116,10 +121,23 @@ couchTests.view_errors = function(debug) {
T(e.error == "query_parse_error");
}
+ db.view("test/no_reduce", {reduce: false});
+ TEquals(200, db.last_req.status, "reduce=false for map views (without"
+ + " group or group_level) is allowed");
+
try {
db.view("test/with_reduce", {group: true, reduce: false});
T(0 == 1);
} catch(e) {
+ T(db.last_req.status == 400);
+ T(e.error == "query_parse_error");
+ }
+
+ try {
+ db.view("test/with_reduce", {group_level: 1, reduce: false});
+ T(0 == 1);
+ } catch(e) {
+ T(db.last_req.status == 400);
T(e.error == "query_parse_error");
}
@@ -159,5 +177,13 @@ couchTests.view_errors = function(debug) {
T(xhr.status == 500);
result = JSON.parse(xhr.responseText);
T(result.error == "reduce_overflow_error");
+
+ try {
+ db.query(function() {emit(null, null)}, null, {startkey: 2, endkey:1});
+ T(0 == 1);
+ } catch(e) {
+ T(e.error == "query_parse_error");
+ T(e.reason.match(/no rows can match/i));
+ }
});
};