davisp commented on a change in pull request #2666: soft-deletion for database
URL: https://github.com/apache/couchdb/pull/2666#discussion_r401769925
 
 

 ##########
 File path: src/chttpd/test/eunit/chttpd_deleted_dbs_test.erl
 ##########
 @@ -0,0 +1,206 @@
+% 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_deleted_dbs_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),
+    lists:concat(["http://";, Addr, ":", Port, "/"]).
+
+teardown(_Url) ->
+    ok = config:delete("couchdb", "enable_database_recovery", false),
+    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]).
+
+deleted_dbs_test_() ->
+    {
+        "chttpd deleted dbs 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_deleted_dbs/1,
+                    fun should_list_deleted_dbs/1,
+                    fun should_list_deleted_dbs_info/1,
+                    fun should_undelete_db/1,
+                    fun should_remove_deleted_db/1,
+                    fun should_undelete_db_to_target_db/1,
+                    fun should_not_undelete_db_to_existing_db/1
+                ]
+            }
+        }
+    }.
+
+
+should_return_error_for_deleted_dbs(Url) ->
+    ?_test(begin
+        create_and_delete_db(Url),
+        NewDoc = "{\"keys\": [\"db1\"]}",
+        {ok, Code, _, ResultBody} = test_request:post(Url ++ "/_deleted_dbs/",
+            [?CONTENT_JSON, ?AUTH], NewDoc),
 
 Review comment:
   And the error code would also be a 404 then.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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