You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2015/07/01 15:22:04 UTC

[2/3] couch-mrview commit: updated refs/heads/master to 1c10f21

Add tests for design document validations

COUCHDB-537


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/6343efd6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/6343efd6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/6343efd6

Branch: refs/heads/master
Commit: 6343efd6768a3d4d4ff2c6e1b22200f4e4aaca3f
Parents: edb2c85
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Tue Jun 30 21:27:41 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Tue Jun 30 21:32:17 2015 -0400

----------------------------------------------------------------------
 test/couch_mrview_ddoc_validation_tests.erl | 78 ++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/6343efd6/test/couch_mrview_ddoc_validation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_ddoc_validation_tests.erl b/test/couch_mrview_ddoc_validation_tests.erl
new file mode 100644
index 0000000..17cd4d3
--- /dev/null
+++ b/test/couch_mrview_ddoc_validation_tests.erl
@@ -0,0 +1,78 @@
+% 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.
+
+-module(couch_mrview_ddoc_validation_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+setup() ->
+    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_CTX]),
+    ok.
+
+ddoc_validation_test_() ->
+    {
+        "ddoc validation tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_reject_invalid_js_map/1,
+                    fun should_reject_invalid_js_reduce/1,
+                    fun should_reject_invalid_builtin_reduce/1
+                ]
+            }
+        }
+    }.
+
+should_reject_invalid_js_map(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_js_map">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) }{">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({compilation_error, _}, couch_db:update_doc(Db, Doc, [])).
+
+should_reject_invalid_js_reduce(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_js_reduce">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) { emit(null); }">>},
+                {<<"reduce">>, <<"function(k, v, r) }{}">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({compilation_error, _}, couch_db:update_doc(Db, Doc, [])).
+
+should_reject_invalid_builtin_reduce(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_builtin_reduce">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) { emit(null); }">>},
+                {<<"reduce">>, <<"_foobar">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({invalid_design_doc, _}, couch_db:update_doc(Db, Doc, [])).