1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class DatabaseResetTest < ActionDispatch::IntegrationTest
8 slow_test "reset fails when Rails.env != 'test'" do
9 rails_env_was = Rails.env
11 Rails.env = 'production'
12 Rails.application.reload_routes!
13 post '/database/reset', params: {}, headers: auth(:admin)
16 Rails.env = rails_env_was
17 Rails.application.reload_routes!
21 test "reset fails with non-admin token" do
22 post '/database/reset', params: {}, headers: auth(:active)
26 slow_test "database reset doesn't break basic CRUD operations" do
27 active_auth = auth(:active)
28 admin_auth = auth(:admin)
31 post '/database/reset', params: {}, headers: admin_auth
32 assert_response :success
34 post '/arvados/v1/collections', params: {collection: '{}'}, headers: active_auth
35 assert_response :success
36 new_uuid = json_response['uuid']
38 get '/arvados/v1/collections/'+new_uuid, params: {}, headers: active_auth
39 assert_response :success
41 put('/arvados/v1/collections/'+new_uuid,
42 params: {collection: '{"properties":{}}'},
44 assert_response :success
46 delete '/arvados/v1/collections/'+new_uuid, params: {}, headers: active_auth
47 assert_response :success
49 get '/arvados/v1/collections/'+new_uuid, params: {}, headers: active_auth
53 slow_test "roll back database change" do
54 active_auth = auth(:active)
55 admin_auth = auth(:admin)
57 old_uuid = collections(:collection_owned_by_active).uuid
59 post '/database/reset', params: {}, headers: admin_auth
60 assert_response :success
62 delete '/arvados/v1/collections/' + old_uuid, params: {}, headers: active_auth
63 assert_response :success
64 post '/arvados/v1/collections', params: {collection: '{}'}, headers: active_auth
65 assert_response :success
66 new_uuid = json_response['uuid']
69 post '/database/reset', params: {}, headers: admin_auth
70 assert_response :success
72 # New collection should disappear. Old collection should reappear.
73 get '/arvados/v1/collections/'+new_uuid, params: {}, headers: active_auth
75 get '/arvados/v1/collections/'+old_uuid, params: {}, headers: active_auth
76 assert_response :success