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_text 'supplied_script_version: (none)'
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"