You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by iilyak <gi...@git.apache.org> on 2016/09/22 23:28:08 UTC

[GitHub] couchdb-couch pull request #200: Adding test suite for trancated _update

GitHub user iilyak opened a pull request:

    https://github.com/apache/couchdb-couch/pull/200

    Adding test suite for trancated _update

    Test suite for https://github.com/apache/couchdb-chttpd/pull/140
    
    COUCHDB-3158

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloudant/couchdb-couch 69425-handle-truncated-req-in-recv_body

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-couch/pull/200.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #200
    
----
commit 21c374f1dc049d35089092fc513d226f6580a3a6
Author: ILYA Khlopotov <ii...@apache.org>
Date:   2016-09-22T23:11:02Z

    Adding test suite for trancated _update
    
    COUCHDB-3158

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request #200: Adding test suite for trancated _update

Posted by kxepal <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch issue #200: Adding test suite for trancated _update

Posted by eiri <gi...@git.apache.org>.
Github user eiri commented on the issue:

    https://github.com/apache/couchdb-couch/pull/200
  
    Passed locally. LGTM.
    
    ```
    Compiled test/couchdb_mrview_tests.erl
    ======================== EUnit ========================
    module 'couchdb_mrview_tests'
      Check show functionality
        clustered
          couchdb_mrview_tests:83: should_return_incomplete...[0.056 s] ok
          [done in 0.059 s]
        backdoor
          couchdb_mrview_tests:83: should_return_incomplete...[0.018 s] ok
          [done in 0.022 s]
    [os_mon] cpu supervisor port (cpu_sup): Erlang has closed
        [done in 0.543 s]
      [done in 1.914 s]
    =======================================================
      2 tests passed.
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch pull request #200: Adding test suite for trancated _update

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/couchdb-couch/pull/200


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---