Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch/pull/200#discussion_r80184463
  
    --- Diff: test/couchdb_mrview_tests.erl ---
    @@ -0,0 +1,165 @@
    +% 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(couchdb_mrview_tests).
    +
    +-include_lib("couch/include/couch_eunit.hrl").
    +-include_lib("couch/include/couch_db.hrl").
    +
    +
    +
    +-define(DDOC, {[
    +    {<<"_id">>, <<"_design/foo">>},
    +    {<<"shows">>, {[
    +        {<<"bar">>, <<"function(doc, req) {return '<h1>wosh</h1>';}">>}
    +    ]}},
    +    {<<"updates">>, {[
    +        {<<"report">>, <<"function(doc, req) {"
    +            "var data = JSON.parse(req.body); "
    +            "return ['test', data];"
    +        "}">>}
    +    ]}}
    +]}).
    +
    +-define(USER, "admin").
    +-define(PASS, "pass").
    +-define(AUTH, {basic_auth, {?USER, ?PASS}}).
    +
    +
    +start() ->
    +    Ctx = test_util:start_couch([chttpd]),
    +    ok = config:set("admins", ?USER, ?PASS, _Persist=false),
    +    Ctx.
    +
    +setup(PortType) ->
    +    ok = meck:new(mochiweb_socket, [passthrough]),
    +    ok = meck:expect(mochiweb_socket, recv, fun mochiweb_socket_recv/3),
    +
    +    DbName = ?tempdb(),
    +    ok = create_db(PortType, DbName),
    +
    +    Host = host_url(PortType),
    +    upload_ddoc(Host, ?b2l(DbName)),
    +    {Host, ?b2l(DbName)}.
    +
    +teardown(Ctx) ->
    +    ok = config:delete("admins", ?USER, _Persist=false),
    +    test_util:stop_couch(Ctx).
    +
    +teardown(PortType, {_Host, DbName}) ->
    +    (catch meck:unload(mochiweb_socket)),
    +    delete_db(PortType, ?l2b(DbName)),
    +    ok.
    +
    +mrview_update_test_() ->
    +    {
    +        "Check show functionality",
    +        {
    +            setup,
    +            fun start/0, fun teardown/1,
    +            [
    +                make_test_case(clustered, [fun 
should_return_incomplete/2]),
    +                make_test_case(backdoor, [fun should_return_incomplete/2])
    +            ]
    +        }
    +    }.
    +
    +make_test_case(Mod, Funs) ->
    +    {
    +        lists:flatten(io_lib:format("~s", [Mod])),
    +        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- 
Funs]}
    +    }.
    +
    +should_return_incomplete(PortType, {Host, DbName}) ->
    +    ?_test(begin
    +         ok = create_doc(PortType, ?l2b(DbName), <<"doc_id">>, {[]}),
    +         ReqUrl = Host ++ "/" ++ DbName ++ 
"/_design/foo/_update/report/doc_id",
    +         {ok, Status, _Headers, Body} =
    +              test_request:post(ReqUrl, [?AUTH], <<"{truncated}">>),
    +         {Props} = jiffy:decode(Body),
    +         ?assertEqual(
    +            <<"bad_request">>, couch_util:get_value(<<"error">>, Props)),
    +         ?assertEqual(
    +            <<"Incomplete">>, couch_util:get_value(<<"reason">>, Props)),
    +         ?assertEqual(400, Status),
    +         ok
    +    end).
    +
    +create_doc(backdoor, DbName, Id, Body) ->
    +    JsonDoc = couch_util:json_apply_field({<<"_id">>, Id}, Body),
    +    Doc = couch_doc:from_json_obj(JsonDoc),
    +    {ok, Db} = couch_db:open(DbName, [?ADMIN_CTX]),
    +    {ok, _} = couch_db:update_docs(Db, [Doc]),
    +    couch_db:ensure_full_commit(Db),
    +    couch_db:close(Db);
    +create_doc(clustered, DbName, Id, Body) ->
    +    JsonDoc = couch_util:json_apply_field({<<"_id">>, Id}, Body),
    +    Doc = couch_doc:from_json_obj(JsonDoc),
    +    {ok, _} = fabric:update_docs(DbName, [Doc], [?ADMIN_CTX]),
    +    ok.
    +
    +create_db(backdoor, DbName) ->
    +    {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
    +    couch_db:close(Db);
    +create_db(clustered, DbName) ->
    +    {ok, Status, _, _} = test_request:put(db_url(DbName), [?AUTH], ""),
    +    assert_success(create_db, Status),
    +    ok.
    +
    +delete_db(backdoor, DbName) ->
    +    couch_server:delete(DbName, [?ADMIN_CTX]);
    +delete_db(clustered, DbName) ->
    +    {ok, Status, _, _} = test_request:delete(db_url(DbName), [?AUTH]),
    +    assert_success(delete_db, Status),
    +    ok.
    +
    +assert_success(create_db, Status) ->
    +    true = lists:member(Status, [201, 202]);
    --- End diff --
    
    Shouldn't explicit `?assert` be used? It produces a bit more informative 
error than badmatch if something will go wrong.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to