X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c0650d1d845b08668445fa5245d0e532b38afb95..cb230b07e0125d819991bc74a1f528740068157d:/services/api/test/functional/arvados/v1/containers_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/containers_controller_test.rb b/services/api/test/functional/arvados/v1/containers_controller_test.rb index 45149b21d9..1f8a7c4315 100644 --- a/services/api/test/functional/arvados/v1/containers_controller_test.rb +++ b/services/api/test/functional/arvados/v1/containers_controller_test.rb @@ -50,28 +50,51 @@ class Arvados::V1::ContainersControllerTest < ActionController::TestCase assert_nil json_response['auth'] end - test "lock and unlock container" do - # lock container + test "lock container" do authorize_with :dispatch1 - post :lock, {id: containers(:queued).uuid} + uuid = containers(:queued).uuid + post :lock, {id: uuid} assert_response :success - container = Container.where(uuid: containers(:queued).uuid).first + assert_nil json_response['mounts'] + assert_nil json_response['command'] + assert_not_nil json_response['auth_uuid'] + assert_not_nil json_response['locked_by_uuid'] + assert_equal containers(:queued).uuid, json_response['uuid'] + assert_equal 'Locked', json_response['state'] + assert_equal containers(:queued).priority, json_response['priority'] + + container = Container.where(uuid: uuid).first assert_equal 'Locked', container.state assert_not_nil container.locked_by_uuid assert_not_nil container.auth_uuid + end - # unlock container - @test_counter = 0 # Reset executed action counter - @controller = Arvados::V1::ContainersController.new + test "unlock container" do authorize_with :dispatch1 - post :unlock, {id: container.uuid} + uuid = containers(:locked).uuid + post :unlock, {id: uuid} assert_response :success - container = Container.where(uuid: container.uuid).first + assert_nil json_response['mounts'] + assert_nil json_response['command'] + assert_nil json_response['auth_uuid'] + assert_nil json_response['locked_by_uuid'] + assert_equal containers(:locked).uuid, json_response['uuid'] + assert_equal 'Queued', json_response['state'] + assert_equal containers(:locked).priority, json_response['priority'] + + container = Container.where(uuid: uuid).first assert_equal 'Queued', container.state assert_nil container.locked_by_uuid assert_nil container.auth_uuid end + test "unlock container locked by different dispatcher" do + authorize_with :dispatch2 + uuid = containers(:locked).uuid + post :unlock, {id: uuid} + assert_response 422 + end + [ [:queued, :lock, :success, 'Locked'], [:queued, :unlock, 422, 'Queued'], @@ -87,4 +110,23 @@ class Arvados::V1::ContainersControllerTest < ActionController::TestCase assert_equal state, Container.where(uuid: uuid).first.state end end + + test 'get current container for token' do + authorize_with :running_container_auth + get :current + assert_response :success + assert_equal containers(:running).uuid, json_response['uuid'] + end + + test 'no container associated with token' do + authorize_with :dispatch1 + get :current + assert_response 404 + end + + test 'try get current container, no token' do + get :current + assert_response 401 + end + end