3 class JobTest < ActiveSupport::TestCase
4 BAD_COLLECTION = "#{'f' * 32}+0"
7 set_user_from_auth :active
10 test "Job without Docker image doesn't get locator" do
13 assert_nil job.docker_image_locator
16 { 'name' => [:links, :docker_image_collection_repository, :name],
17 'hash' => [:links, :docker_image_collection_hash, :name],
18 'locator' => [:collections, :docker_image, :uuid],
19 }.each_pair do |spec_type, (fixture_type, fixture_name, fixture_attr)|
20 test "Job initialized with Docker image #{spec_type} gets locator" do
21 image_spec = send(fixture_type, fixture_name).send(fixture_attr)
22 job = Job.new(runtime_constraints: {'docker_image' => image_spec})
23 assert(job.valid?, "Docker image #{spec_type} was invalid")
24 assert_equal(collections(:docker_image).uuid, job.docker_image_locator)
27 test "Job modified with Docker image #{spec_type} gets locator" do
30 assert_nil job.docker_image_locator
31 image_spec = send(fixture_type, fixture_name).send(fixture_attr)
32 job.runtime_constraints['docker_image'] = image_spec
33 assert(job.valid?, "modified Docker image #{spec_type} was invalid")
34 assert_equal(collections(:docker_image).uuid, job.docker_image_locator)
38 test "removing a Docker runtime constraint removes the locator" do
39 image_locator = collections(:docker_image).uuid
40 job = Job.new(runtime_constraints: {'docker_image' => image_locator})
42 assert_equal(image_locator, job.docker_image_locator)
43 job.runtime_constraints = {}
44 assert(job.valid?, "clearing runtime constraints made the Job invalid")
45 assert_nil job.docker_image_locator
48 test "locate a Docker image with a repository + tag" do
49 image_repo, image_tag =
50 links(:docker_image_collection_tag2).name.split(':', 2)
51 job = Job.new(runtime_constraints:
52 {'docker_image' => image_repo,
53 'docker_image_tag' => image_tag})
54 assert(job.valid?, "Job with Docker tag search invalid")
55 assert_equal(collections(:docker_image).uuid, job.docker_image_locator)
58 test "can't locate a Docker image with a nonexistent tag" do
59 image_repo = links(:docker_image_collection_repository).name
60 image_tag = '__nonexistent tag__'
61 job = Job.new(runtime_constraints:
62 {'docker_image' => image_repo,
63 'docker_image_tag' => image_tag})
64 assert(job.invalid?, "Job with bad Docker tag valid")
67 test "locate a Docker image with a partial hash" do
68 image_hash = links(:docker_image_collection_hash).name[0..24]
69 job = Job.new(runtime_constraints: {'docker_image' => image_hash})
70 assert(job.valid?, "Job with partial Docker image hash failed")
71 assert_equal(collections(:docker_image).uuid, job.docker_image_locator)
74 { 'name' => 'arvados_test_nonexistent',
76 'locator' => BAD_COLLECTION,
77 }.each_pair do |spec_type, image_spec|
78 test "Job validation fails with nonexistent Docker image #{spec_type}" do
79 job = Job.new(runtime_constraints: {'docker_image' => image_spec})
80 assert(job.invalid?, "nonexistent Docker image #{spec_type} was valid")
84 test "Job validation fails with non-Docker Collection constraint" do
85 job = Job.new(runtime_constraints:
86 {'docker_image' => collections(:foo_file).uuid})
87 assert(job.invalid?, "non-Docker Collection constraint was valid")
90 test "can't create Job with Docker image locator" do
92 job = Job.new(docker_image_locator: BAD_COLLECTION)
93 rescue ActiveModel::MassAssignmentSecurity::Error
94 # Test passes - expected attribute protection
96 assert_nil job.docker_image_locator
100 test "can't assign Docker image locator to Job" do
103 Job.docker_image_locator = BAD_COLLECTION
105 # Test passes - expected attribute protection
107 assert_nil job.docker_image_locator