1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
10 command: ['echo', 'hello'],
11 container_image: 'test',
16 test 'create with scheduling parameters' do
17 authorize_with :active
19 sp = {'partitions' => ['test1', 'test2']}
20 post :create, params: {
21 container_request: minimal_cr.merge(scheduling_parameters: sp.dup)
23 assert_response :success
25 cr = JSON.parse(@response.body)
26 assert_not_nil cr, 'Expected container request'
27 assert_equal sp, cr['scheduling_parameters']
30 test "secret_mounts not in #create responses" do
31 authorize_with :active
33 post :create, params: {
34 container_request: minimal_cr.merge(
35 secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}}),
37 assert_response :success
39 resp = JSON.parse(@response.body)
40 refute resp.has_key?('secret_mounts')
42 req = ContainerRequest.where(uuid: resp['uuid']).first
43 assert_equal 'bar', req.secret_mounts['/foo']['content']
46 test "update with secret_mounts" do
47 authorize_with :active
48 req = container_requests(:uncommitted)
50 patch :update, params: {
53 secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}},
56 assert_response :success
58 resp = JSON.parse(@response.body)
59 refute resp.has_key?('secret_mounts')
62 assert_equal 'bar', req.secret_mounts['/foo']['content']
65 test "update without deleting secret_mounts" do
66 authorize_with :active
67 req = container_requests(:uncommitted)
68 req.update_attributes!(secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}})
70 patch :update, params: {
73 command: ['echo', 'test'],
76 assert_response :success
78 resp = JSON.parse(@response.body)
79 refute resp.has_key?('secret_mounts')
82 assert_equal 'bar', req.secret_mounts['/foo']['content']
85 test "runtime_token not in #create responses" do
86 authorize_with :active
88 post :create, params: {
89 container_request: minimal_cr.merge(
90 runtime_token: api_client_authorizations(:spectator).token)
92 assert_response :success
94 resp = JSON.parse(@response.body)
95 refute resp.has_key?('runtime_token')
97 req = ContainerRequest.where(uuid: resp['uuid']).first
98 assert_equal api_client_authorizations(:spectator).token, req.runtime_token
101 %w(Running Complete).each do |state|
102 test "filter on container.state = #{state}" do
103 authorize_with :active
104 get :index, params: {
105 filters: [['container.state', '=', state]],
107 assert_response :success
108 assert_operator json_response['items'].length, :>, 0
109 json_response['items'].each do |cr|
110 assert_equal state, Container.find_by_uuid(cr['container_uuid']).state
115 test "filter on container success" do
116 authorize_with :active
117 get :index, params: {
119 ['container.state', '=', 'Complete'],
120 ['container.exit_code', '=', '0'],
123 assert_response :success
124 assert_operator json_response['items'].length, :>, 0
125 json_response['items'].each do |cr|
126 assert_equal 'Complete', Container.find_by_uuid(cr['container_uuid']).state
127 assert_equal 0, Container.find_by_uuid(cr['container_uuid']).exit_code
131 test "filter on container subproperty runtime_status[foo] = bar" do
132 ctr = containers(:running)
133 act_as_system_user do
134 ctr.update_attributes!(runtime_status: {foo: 'bar'})
136 authorize_with :active
137 get :index, params: {
139 ['container.runtime_status.foo', '=', 'bar'],
142 assert_response :success
143 assert_equal [ctr.uuid], json_response['items'].collect { |cr| cr['container_uuid'] }.uniq