iilyak commented on a change in pull request #1082: Introduce new _dbs_info 
endpoint to get info of a list of databases
URL: https://github.com/apache/couchdb/pull/1082#discussion_r164188123
 
 

 ##########
 File path: src/chttpd/test/chttpd_dbs_info_test.erl
 ##########
 @@ -0,0 +1,169 @@
+% 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(chttpd_dbs_info_test).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+-define(USER, "chttpd_db_test_admin").
+-define(PASS, "pass").
+-define(AUTH, {basic_auth, {?USER, ?PASS}}).
+-define(CONTENT_JSON, {"Content-Type", "application/json"}).
+
+
+setup() ->
+    Hashed = couch_passwords:hash_admin_password(?PASS),
+    ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
+    Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
+    Port = mochiweb_socket_server:get(chttpd, port),
+    Url = lists:concat(["http://";, Addr, ":", Port, "/"]),
+    Db1Url = lists:concat([Url, "db1"]),
+    create_db(Db1Url),
+    Db2Url = lists:concat([Url, "db2"]),
+    create_db(Db2Url),
+    Url.
+
+teardown(Url) ->
+    Db1Url = lists:concat([Url, "db1"]),
+    Db2Url = lists:concat([Url, "db2"]),
+    delete_db(Db1Url),
+    delete_db(Db2Url),
+    ok = config:delete("admins", ?USER, _Persist=false).
+
+create_db(Url) ->
+    {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
+    ?assert(Status =:= 201 orelse Status =:= 202).
+
+delete_db(Url) ->
+    {ok, 200, _, _} = test_request:delete(Url, [?AUTH]).
+
+dbs_info_test_() ->
+    {
+        "chttpd dbs info tests",
+        {
+            setup,
+            fun chttpd_test_util:start_couch/0, fun 
chttpd_test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_return_error_for_get_db_info/1,
+                    fun should_return_dbs_info_for_single_db/1,
+                    fun should_return_dbs_info_for_multiple_dbs/1,
+                    fun should_return_error_for_exceeded_keys/1,
+                    fun should_return_error_for_missing_keys/1,
+                    fun should_return_dbs_info_for_dbs_with_mixed_state/1
+                ]
+            }
+        }
+    }.
+
+
+should_return_error_for_get_db_info(Url) ->
+    ?_test(begin
+        {ok, Code, _, ResultBody} = test_request:get(Url ++ "/_dbs_info?"
+            ++ "keys=[\"db1\"]", [?CONTENT_JSON, ?AUTH]),
+        {Body} = jiffy:decode(ResultBody),
+        [
+            ?assertEqual(405, Code),
 
 Review comment:
   Please swap the order of assertions for every test in a test suite.
   You would have:
    1. assert on error 
    2. assert on return code
   
   If `couch_util:get_value(<<"error">>, Body))` assertion goes first we would 
see a reason in test failure. Currently we would see return code don't match 
but not a meaningful error. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to