diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-09-04 09:29:21 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-09-15 12:49:02 -0500 |
commit | 8cd1792235b724db47d25e322178e06a978ed690 (patch) | |
tree | 5a56b20ab58d565f8542342157fc9811c8e79ff2 | |
parent | a626125ad536f0a8003a50136bcbd7841264aa15 (diff) | |
download | couchdb-8cd1792235b724db47d25e322178e06a978ed690.tar.gz |
Move error reporting test to EUnit
This test doesn't fail correctly any longer. Rather than attempting to
create a new pathological view case I've just moved it to eunit where we
can use meck to throw errors directly.
-rw-r--r-- | src/couch_views/test/couch_views_error_test.erl | 102 | ||||
-rw-r--r-- | test/elixir/test/map_test.exs | 32 |
2 files changed, 102 insertions, 32 deletions
diff --git a/src/couch_views/test/couch_views_error_test.erl b/src/couch_views/test/couch_views_error_test.erl new file mode 100644 index 000000000..8b6399e0e --- /dev/null +++ b/src/couch_views/test/couch_views_error_test.erl @@ -0,0 +1,102 @@ +% 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_views_error_test). + +-include_lib("eunit/include/eunit.hrl"). +-include_lib("couch/include/couch_db.hrl"). +-include_lib("couch/include/couch_eunit.hrl"). +-include_lib("fabric/test/fabric2_test.hrl"). + +-define(USER, "chttpd_db_test_admin"). +-define(PASS, "pass"). +-define(AUTH, {basic_auth, {?USER, ?PASS}}). +-define(CONTENT_JSON, {"Content-Type", "application/json"}). + + +error_test_() -> + { + "Test views report errors", + { + setup, + fun setup/0, + fun teardown/1, + { + foreach, + fun foreach_setup/0, + fun foreach_teardown/1, + [ + ?TDEF_FE(view_reports_error) + ] + } + } + }. + + +setup() -> + Ctx = test_util:start_couch([ + fabric, + chttpd, + couch_jobs, + couch_js, + couch_views + ]), + Hashed = couch_passwords:hash_admin_password(?PASS), + ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false), + Ctx. + + +teardown(Ctx) -> + test_util:stop_couch(Ctx). + + +foreach_setup() -> + Addr = config:get("chttpd", "bind_address", "127.0.0.1"), + Port = mochiweb_socket_server:get(chttpd, port), + {ok, Db} = fabric2_db:create(?tempdb(), [{user_ctx, ?ADMIN_USER}]), + DbName = fabric2_db:name(Db), + Url = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(DbName)]), + {Db, Url}. + + +foreach_teardown({Db, _}) -> + meck:unload(), + ok = fabric2_db:delete(fabric2_db:name(Db), []). + + +view_reports_error({Db, Url}) -> + meck:new(couch_views_batch, [passthrough]), + meck:expect(couch_views_batch, start, fun(_) -> + erlang:error({erlfdb_error, 2101}) + end), + + {ok, _} = fabric2_db:update_doc(Db, ddoc(), []), + + ViewUrl = lists:concat([Url, "/_design/foo/_view/bar"]), + {ok, Status, _Headers, Body} = test_request:get(ViewUrl, [?AUTH]), + + ?assertEqual(500, Status), + {Props} = couch_util:json_decode(Body), + {<<"error">>, Error} = lists:keyfind(<<"error">>, 1, Props), + ?assertEqual(<<"foundationdb_error">>, Error). + + +ddoc() -> + couch_doc:from_json_obj({[ + {<<"_id">>, <<"_design/foo">>}, + {<<"language">>, <<"javascript">>}, + {<<"views">>, {[ + {<<"bar">>, {[ + {<<"map">>, <<"function(doc) {emit(doc.value, doc.value);}">>} + ]}} + ]}} + ]}). diff --git a/test/elixir/test/map_test.exs b/test/elixir/test/map_test.exs index 9254cc4c3..3e2765fbd 100644 --- a/test/elixir/test/map_test.exs +++ b/test/elixir/test/map_test.exs @@ -503,38 +503,6 @@ defmodule ViewMapTest do assert keys == ["bar"] end - test "send error for failed indexing", context do - db_name = context[:db_name] - - docs = [ - %{_id: "doc1", foo: "foo", bar: "bar"}, - %{ - _id: "_design/view1", - views: %{ - view: %{ - map: """ - function (doc) { - for (var i=0; i<10000; i++) { - emit({doc: doc._id + 1}, doc._id); - } - } - """ - } - } - } - ] - - resp = Couch.post("/#{db_name}/_bulk_docs", body: %{:docs => docs}) - assert resp.status_code == 201 - - url = "/#{db_name}/_design/view1/_view/view" - - resp = Couch.get(url, timeout: 500_000) - assert resp.status_code == 500 - %{:body => %{"error" => error}} = resp - assert error == "foundationdb_error" - end - test "descending=true query with startkey_docid", context do db_name = context[:db_name] |