3 class Arvados::V1::ContainersControllerTest < ActionController::TestCase
5 authorize_with :system_user
8 command: ['echo', 'hello'],
9 container_image: 'test',
13 assert_response :success
16 [Container::Queued, Container::Complete].each do |state|
17 test "cannot get auth in #{state} state" do
18 authorize_with :dispatch1
19 get :auth, id: containers(:queued).uuid
24 test 'cannot get auth with wrong token' do
25 authorize_with :dispatch1
26 c = containers(:queued)
27 assert c.lock, show_errors(c)
29 authorize_with :system_user
35 authorize_with :dispatch1
36 c = containers(:queued)
37 assert c.lock, show_errors(c)
39 assert_response :success
40 assert_operator 32, :<, json_response['api_token'].length
41 assert_equal 'arvados#apiClientAuthorization', json_response['kind']
44 test 'no auth in container response' do
45 authorize_with :dispatch1
46 c = containers(:queued)
47 assert c.lock, show_errors(c)
49 assert_response :success
50 assert_nil json_response['auth']
53 test "lock container" do
54 authorize_with :dispatch1
55 uuid = containers(:queued).uuid
56 post :lock, {id: uuid}
57 assert_response :success
58 assert_nil json_response['mounts']
59 assert_nil json_response['command']
60 assert_not_nil json_response['auth_uuid']
61 assert_not_nil json_response['locked_by_uuid']
62 assert_equal containers(:queued).uuid, json_response['uuid']
63 assert_equal 'Locked', json_response['state']
64 assert_equal containers(:queued).priority, json_response['priority']
66 container = Container.where(uuid: uuid).first
67 assert_equal 'Locked', container.state
68 assert_not_nil container.locked_by_uuid
69 assert_not_nil container.auth_uuid
72 test "unlock container" do
73 authorize_with :dispatch1
74 uuid = containers(:locked).uuid
75 post :unlock, {id: uuid}
76 assert_response :success
77 assert_nil json_response['mounts']
78 assert_nil json_response['command']
79 assert_nil json_response['auth_uuid']
80 assert_nil json_response['locked_by_uuid']
81 assert_equal containers(:locked).uuid, json_response['uuid']
82 assert_equal 'Queued', json_response['state']
83 assert_equal containers(:locked).priority, json_response['priority']
85 container = Container.where(uuid: uuid).first
86 assert_equal 'Queued', container.state
87 assert_nil container.locked_by_uuid
88 assert_nil container.auth_uuid
91 test "unlock container locked by different dispatcher" do
92 authorize_with :dispatch2
93 uuid = containers(:locked).uuid
94 post :unlock, {id: uuid}
99 [:queued, :lock, :success, 'Locked'],
100 [:queued, :unlock, 422, 'Queued'],
101 [:locked, :lock, 422, 'Locked'],
102 [:running, :lock, 422, 'Running'],
103 [:running, :unlock, 422, 'Running'],
104 ].each do |fixture, action, response, state|
105 test "state transitions from #{fixture } to #{action}" do
106 authorize_with :dispatch1
107 uuid = containers(fixture).uuid
108 post action, {id: uuid}
109 assert_response response
110 assert_equal state, Container.where(uuid: uuid).first.state
114 test 'get current container for token' do
115 authorize_with :running_container_auth
117 assert_response :success
118 assert_equal containers(:running).uuid, json_response['uuid']
121 test 'no container associated with token' do
122 authorize_with :dispatch1
127 test 'try get current container, no token' do