3 class ContainerTest < ActiveSupport::TestCase
4 def check_illegal_modify c
6 c.command = ["echo", "bar"]
7 assert_raises(ActiveRecord::RecordInvalid) do
12 c.container_image = "img2"
13 assert_raises(ActiveRecord::RecordInvalid) do
19 assert_raises(ActiveRecord::RecordInvalid) do
24 c.environment = {"FOO" => "BAR"}
25 assert_raises(ActiveRecord::RecordInvalid) do
30 c.mounts = {"FOO" => "BAR"}
31 assert_raises(ActiveRecord::RecordInvalid) do
36 c.output_path = "/tmp3"
37 assert_raises(ActiveRecord::RecordInvalid) do
42 c.runtime_constraints = {"FOO" => "BAR"}
43 assert_raises(ActiveRecord::RecordInvalid) do
48 def check_bogus_states c
51 assert_raises(ActiveRecord::RecordInvalid) do
57 assert_raises(ActiveRecord::RecordInvalid) do
62 def check_no_change_from_complete c
63 check_illegal_modify c
68 assert_raises(ActiveRecord::RecordInvalid) do
74 assert_raises(ActiveRecord::RecordInvalid) do
80 assert_raises(ActiveRecord::RecordInvalid) do
86 assert_raises(ActiveRecord::RecordInvalid) do
91 test "Container create" do
94 c.command = ["echo", "foo"]
95 c.container_image = "img"
98 c.mounts = {"BAR" => "FOO"}
99 c.output_path = "/tmp"
101 c.runtime_constraints = {}
104 check_illegal_modify c
113 test "Container running" do
114 act_as_system_user do
116 c.command = ["echo", "foo"]
117 c.container_image = "img"
118 c.output_path = "/tmp"
123 assert_raises(ActiveRecord::RecordInvalid) do
131 check_illegal_modify c
136 assert_raises(ActiveRecord::RecordInvalid) do
146 test "Container queued cancel" do
147 act_as_system_user do
149 c.command = ["echo", "foo"]
150 c.container_image = "img"
151 c.output_path = "/tmp"
155 c.state = "Cancelled"
158 check_no_change_from_complete c
162 test "Container running cancel" do
163 act_as_system_user do
165 c.command = ["echo", "foo"]
166 c.container_image = "img"
167 c.output_path = "/tmp"
175 c.state = "Cancelled"
178 check_no_change_from_complete c
182 test "Container create forbidden for non-admin" do
183 set_user_from_auth :active_trustedclient
185 c.command = ["echo", "foo"]
186 c.container_image = "img"
189 c.mounts = {"BAR" => "FOO"}
190 c.output_path = "/tmp"
192 c.runtime_constraints = {}
193 assert_raises(ArvadosModel::PermissionDeniedError) do
198 test "Container only set exit code on complete" do
199 act_as_system_user do
201 c.command = ["echo", "foo"]
202 c.container_image = "img"
203 c.output_path = "/tmp"
212 assert_raises(ActiveRecord::RecordInvalid) do
218 c.state = "Cancelled"
219 assert_raises(ActiveRecord::RecordInvalid) do