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 container = Container.where(uuid: uuid).first
59 assert_equal 'Locked', container.state
60 assert_not_nil container.locked_by_uuid
61 assert_not_nil container.auth_uuid
64 test "unlock container" do
65 authorize_with :dispatch1
66 uuid = containers(:locked).uuid
67 post :unlock, {id: uuid}
68 assert_response :success
69 container = Container.where(uuid: uuid).first
70 assert_equal 'Queued', container.state
71 assert_nil container.locked_by_uuid
72 assert_nil container.auth_uuid
76 [:queued, :lock, :success, 'Locked'],
77 [:queued, :unlock, 422, 'Queued'],
78 [:locked, :lock, 422, 'Locked'],
79 [:running, :lock, 422, 'Running'],
80 [:running, :unlock, 422, 'Running'],
81 ].each do |fixture, action, response, state|
82 test "state transitions from #{fixture } to #{action}" do
83 authorize_with :dispatch1
84 uuid = containers(fixture).uuid
85 post action, {id: uuid}
86 assert_response response
87 assert_equal state, Container.where(uuid: uuid).first.state