@@ -139,16 +139,19 @@ def test_load_task_invalid_task(run_load_task):
139139 task = {}
140140 assert run_load_task (task )[0 ] == 1
141141
142- task ["tags " ] = {"worker-implementation" : "generic-worker" }
142+ task ["payload " ] = {}
143143 assert run_load_task (task )[0 ] == 1
144144
145- task ["tags" ]["worker-implementation" ] = "docker-worker"
146- task ["payload" ] = {"command" : []}
145+ task ["payload" ] = {"command" : [], "image" : {"type" : "task-image" }}
147146 assert run_load_task (task )[0 ] == 1
148147
149148 task ["payload" ]["command" ] = ["echo" , "foo" ]
150149 assert run_load_task (task )[0 ] == 1
151150
151+ task ["payload" ]["image" ]["type" ] = "foobar"
152+ task ["payload" ]["command" ] = ["run-task" , "--" , "bash" , "-c" , "echo foo" ]
153+ assert run_load_task (task )[0 ] == 1
154+
152155
153156def test_load_task (run_load_task ):
154157 image_task_id = "def"
@@ -161,7 +164,7 @@ def test_load_task(run_load_task):
161164 "--" ,
162165 "echo foo" ,
163166 ],
164- "image" : {"taskId" : image_task_id },
167+ "image" : {"taskId" : image_task_id , "type" : "task-image" },
165168 },
166169 "tags" : {"worker-implementation" : "docker-worker" },
167170 }
@@ -211,9 +214,8 @@ def test_load_task_env_and_remove(run_load_task):
211214 "echo foo" ,
212215 ],
213216 "env" : {"FOO" : "BAR" , "BAZ" : 1 },
214- "image" : {"taskId" : image_task_id },
217+ "image" : {"taskId" : image_task_id , "type" : "task-image" },
215218 },
216- "tags" : {"worker-implementation" : "docker-worker" },
217219 }
218220 ret , mocks = run_load_task (task , remove = True )
219221 assert ret == 0
@@ -222,3 +224,64 @@ def test_load_task_env_and_remove(run_load_task):
222224 actual = mocks ["subprocess_run" ].call_args [0 ][0 ]
223225 assert re .match (r"--env-file=/tmp/tmp.*" , actual [4 ])
224226 assert actual [5 ] == "--rm"
227+
228+
229+ @pytest .mark .parametrize (
230+ "image" ,
231+ [
232+ pytest .param ({"type" : "task-image" , "taskId" : "xyz" }, id = "task_image" ),
233+ pytest .param (
234+ {"type" : "indexed-image" , "namespace" : "project.some-namespace.latest" },
235+ id = "indexed_image" ,
236+ ),
237+ ],
238+ )
239+ def test_load_task_with_different_image_types (
240+ mocker ,
241+ run_load_task ,
242+ image ,
243+ ):
244+ task_id = "abc"
245+ image_task_id = "xyz"
246+ task = {
247+ "payload" : {
248+ "command" : [
249+ "/usr/bin/run-task" ,
250+ "--task-cwd=/builds/worker" ,
251+ "--" ,
252+ "echo" ,
253+ "test" ,
254+ ],
255+ "image" : image ,
256+ },
257+ "tags" : {"worker-implementation" : "docker-worker" },
258+ }
259+
260+ mocker .patch .object (docker , "find_task_id" , return_value = image_task_id )
261+
262+ ret , mocks = run_load_task (task )
263+ assert ret == 0
264+
265+ mocks ["get_task_definition" ].assert_called_once_with (task_id )
266+ mocks ["load_image_by_task_id" ].assert_called_once_with (image_task_id )
267+
268+
269+ def test_load_task_with_unsupported_image_type (capsys , run_load_task ):
270+ task = {
271+ "payload" : {
272+ "command" : [
273+ "/usr/bin/run-task" ,
274+ "--task-cwd=/builds/worker" ,
275+ "--" ,
276+ "echo foo" ,
277+ ],
278+ "image" : {"type" : "unsupported-type" , "path" : "/some/path" },
279+ },
280+ "tags" : {"worker-implementation" : "docker-worker" },
281+ }
282+
283+ ret , mocks = run_load_task (task )
284+ assert ret == 1
285+
286+ out , _ = capsys .readouterr ()
287+ assert "Tasks with unsupported-type images are not supported!" in out
0 commit comments