4 require 'integration_helper'
6 class JobsTest < ActionDispatch::IntegrationTest
13 def fakepipe_with_log_data
15 "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 1\n" +
16 "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 2\n" +
17 "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0 log message 3\n"
18 StringIO.new content, 'r'
21 test "add job description" do
22 job = api_fixture('jobs')['nearly_finished_job']
23 visit page_with_token("active", "/jobs/#{job['uuid']}")
25 # edit job description
26 within('.arv-description-as-subtitle') do
27 find('.fa-pencil').click
28 find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
29 find('.editable-submit').click
32 # Verify edited description
33 assert_no_text '*Textile description for job*'
34 assert_text 'Textile description for job'
35 assert_selector 'a[href="/"]', text: 'Go to dashboard'
38 test "view job log" do
39 job = api_fixture('jobs')['job_with_real_log']
41 IO.expects(:popen).returns(fakepipe_with_log_data)
43 visit page_with_token("active", "/jobs/#{job['uuid']}")
44 assert page.has_text? job['script_version']
46 find(:xpath, "//a[@href='#Log']").click
48 assert page.has_text? 'Started at'
49 assert page.has_text? 'Finished at'
50 assert page.has_text? 'log message 1'
51 assert page.has_text? 'log message 2'
52 assert page.has_text? 'log message 3'
53 assert page.has_no_text? 'Showing only 100 bytes of this log'
56 test 'view partial job log' do
57 # This config will be restored during teardown by ../test_helper.rb:
58 Rails.configuration.log_viewer_max_bytes = 100
60 IO.expects(:popen).returns(fakepipe_with_log_data)
61 job = api_fixture('jobs')['job_with_real_log']
63 visit page_with_token("active", "/jobs/#{job['uuid']}")
64 assert page.has_text? job['script_version']
66 find(:xpath, "//a[@href='#Log']").click
68 assert page.has_text? 'Showing only 100 bytes of this log'
71 test 'view log via keep-web redirect' do
74 token = api_fixture('api_client_authorizations')['active']['api_token']
75 logdata = fakepipe_with_log_data.read
76 logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
77 assert $?.success?, $?
81 job = Job.find api_fixture('jobs')['running']['uuid']
82 mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
83 logcollection = Collection.create(manifest_text: mtxt)
84 job.update_attributes log: logcollection.portable_data_hash
86 visit page_with_token 'active', '/jobs/'+job.uuid
87 find('a[href="#Log"]').click
88 assert_text 'log message 1'
92 ['foobar', false, false],
93 ['job_with_latest_version', true, false],
94 ['job_with_latest_version', true, true],
95 ].each do |job_name, expect_options, use_latest|
96 test "Rerun #{job_name} job, expect options #{expect_options},
97 and use latest version option #{use_latest}" do
98 job = api_fixture('jobs')[job_name]
99 visit page_with_token 'active', '/jobs/'+job['uuid']
102 assert_text 'supplied_script_version: master'
104 assert_no_text 'supplied_script_version'
107 assert_triggers_dom_event 'shown.bs.modal' do
108 find('a,button', text: 'Re-run job...').click
110 within('.modal-dialog') do
111 assert_selector 'a,button', text: 'Cancel'
113 page.choose("job_script_version_#{job['supplied_script_version']}")
118 # Re-running jobs doesn't currently work because the test API
119 # server has no git repository to check against. For now, check
120 # that the error message says something appropriate for that
122 if expect_options && use_latest
123 assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
125 assert_text "Script version #{job['script_version']} does not resolve to a commit"
132 ['job_reader2', false],
133 ].each do |user, readable|
134 test "view job with components as #{user} user" do
135 job = api_fixture('jobs')['running_job_with_components']
136 component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
137 component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
138 component2_child1 = api_fixture('jobs')['previous_job_run']
139 component2_child2 = api_fixture('jobs')['running']
141 visit page_with_token(user, "/jobs/#{job['uuid']}")
142 assert page.has_text? job['script_version']
143 assert page.has_no_text? 'script_parameters'
145 # The job_reader2 is allowed to read job, component2, and component2_child1,
146 # and component2_child2 only as a component of the pipeline component2
148 assert page.has_link? 'component1'
149 assert page.has_link? 'component2'
151 assert page.has_no_link? 'component1'
152 assert page.has_link? 'component2'
156 click_link('component1')
157 within('#collapse1') do
158 assert(has_text? component1['uuid'])
159 assert(has_text? component1['script_version'])
160 assert(has_text? 'script_parameters')
162 click_link('component1')
165 click_link('component2')
166 within('.panel-collapse') do
167 assert(has_text? component2['uuid'])
168 assert(has_text? component2['script_version'])
169 assert(has_no_text? 'script_parameters')
170 assert(has_link? 'previous')
171 assert(has_link? 'running')
173 click_link('previous')
174 within('.panel-collapse') do
175 assert(has_text? component2_child1['uuid'])
176 assert(has_text? component2_child1['script_version'])
178 click_link('previous')
180 click_link('running')
181 within('.panel-collapse') do
182 assert(has_text? component2_child2['uuid'])
184 assert(has_text? component2_child2['script_version'])
186 assert(has_no_text? component2_child2['script_version'])