diff --git a/config.ru b/config.ru index efd4dd4df1bede096d9ca638c4bc3b408950f598..b1ce091f5558d77e3ba094097022a536b4ef8db9 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,7 @@ require 'debci/api' require 'debci/self_service' require 'debci/frontend' +require 'debci/status' LISTING = <<~HTMLBLOCK.freeze <!DOCTYPE html> @@ -56,6 +57,9 @@ app = Rack::Builder.new do map '/user' do run Debci::SelfService end + map '/status' do + run Debci::Status + end end run app diff --git a/lib/debci/html.rb b/lib/debci/html.rb index 9b2ad24013020765c3aaf2c554ab7d6e8ba71365..fabf8fec08795ba2a366c68687184b5fb631edf5 100644 --- a/lib/debci/html.rb +++ b/lib/debci/html.rb @@ -33,14 +33,6 @@ module Debci end html.index('index.html') - html.status('status/index.html') - html.status_alerts('status/alerts/index.html') - html.status_slow('status/slow/index.html') - html.status_pending_jobs('status/pending') - html.status_failing('status/failing') - html.reject_list - html.blacklist - html.platform_specific_issues('status/platform-specific-issues') end def update_package(package, suite = nil, arch = nil) @@ -241,98 +233,8 @@ module Debci expand_template(:index, filename) end - def status(filename) - @status_nav = load_template(:status_nav) - expand_template(:status, filename) - end - - def status_alerts(filename) - # Packages with at least one visible tmpfail status - @tmpfail = Debci::Job.tmpfail.visible - @alert_number = @tmpfail.length - expand_template(:status_alerts, filename) - end - - def status_slow(filename) - @slow = Debci::Job.slow.sort_by { |j| j.package.name } - expand_template(:status_slow, filename) - end - - def status_pending_jobs(dirname) - @status_nav = load_template(:status_nav) - @status_per_page = Debci.config.pending_status_per_page.to_i - @pending_jobs = Debci::Job.pending.count - - @suites_jobs = Hash[Debci.config.suite_list.map do |x| - [x, Debci::Job.pending.where(suite: x).count] - end - ] - generate_status_pending(dirname, nil) # For 'All suites' - @suites_jobs.each_key { |suite| generate_status_pending(dirname, suite) } - end - - def status_failing(dirname) - @status_nav = load_template(:status_nav) - - jobs = Debci::Job.fail - @packages_per_page = Debci.config.failing_packages_per_page - - generate_status_failing(dirname, jobs) - - Debci.config.suite_list.each do |suite| - generate_status_failing(dirname, jobs, suite) - end - end - - def platform_specific_issues(dirname) - @status_nav = load_template(:status_nav) - - @filters = { - "#{dirname}": ["All", -1], - "#{dirname}/last_thirty_days": ["Last 30 Days", 30], - "#{dirname}/last_one_eighty_days": ["Last 180 Days", 180], - "#{dirname}/last_year": ["Last Year", 365] - } - - issues = Debci::Job.platform_specific_issues - @filters.each do |target, filter| - generate_platform_specific_issues(issues, target, filter) - end - end - - def reject_list - @status_nav = load_template(:status_nav) - @reject_list = Debci.reject_list - expand_template(:reject_list, 'status/reject_list/index.html') - end - - def blacklist - abs_filename = File.join(root_directory, 'status/blacklist/index.html') - FileUtils.mkdir_p(File.dirname(abs_filename)) - - File.open(abs_filename, 'w') do |f| - blacklist_html = File.join(File.dirname(__FILE__), 'html/templates/blacklist.erb') - File.open(blacklist_html, 'r') do |html| - f.write(html.read) - end - end - end - - # expand { SUITE } macro in URLs - def expand_url(url, suite) - url && url.gsub('{SUITE}', suite) - end - private - def history_url(job) - "/packages/#{job.package.prefix}/#{job.package.name}/#{job.suite}/#{job.arch}/" - end - - def package_url(package) - "/packages/#{package.prefix}/#{package.name}/" - end - def templates @templates ||= {} end @@ -375,103 +277,5 @@ module Debci File.read(file_path) end end - - def generate_platform_specific_issues(issues, target, filter) - @issues = issues - - n = filter[1] - if n > 0 - cutoff = Time.now - n.days - @issues = @issues.select do |_, statuses| - statuses.any? do |status| - status.date && status.date > cutoff - end - end - end - expand_template(:platform_specific_issues, "#{target}/index.html") - end - - def generate_status_pending(dirname, suite) - if suite - @pending = Debci::Job.pending.where(suite: suite) - base = "#{dirname}/#{suite}" - else - @pending = Debci::Job.pending - base = dirname - end - - @current_page = "#{base}/all" - expand_template(:status_pending_jobs, @current_page + '/' \ - 'index.html') - @current_page = base - @pending = @pending.last(@status_per_page) - expand_template(:status_pending_jobs, "#{@current_page}/index.html") - end - - # Sorts packages by last updated date, then names - def sort_packages_by_date(packages, suite = nil) - packages.sort do |x, y| - x_date = x.last_updated_at(suite) - y_date = y.last_updated_at(suite) - if x_date && y_date - y_date <=> x_date - elsif x_date || y_date - x_date ? -1 : 1 - else - x.name <=> y.name - end - end - end - - def generate_status_failing(dirname, jobs, suite = nil) - base = "#{dirname}#{"/#{suite}" if suite}" - @suite = suite - - jobs = jobs.where(suite: suite) if suite - jobs = jobs.order('date DESC') - - generate_status_failing_index(jobs, base) - generate_status_failing_all(jobs, base) - generate_status_failing_always_failing(jobs, base) - generate_status_failing_had_success(jobs, base) - end - - def status_failing_title(title) - @suite && [title, "on", @suite].join(' ') || title - end - - def generate_status_failing_all(jobs, base) - @title = 'All failures' - @jobs = jobs - - filename = "#{base}/all/index.html" - expand_template(:status_failing, filename) - end - - def generate_status_failing_index(jobs, base) - @title = status_failing_title( - 'Last %<packages_per_page>d failures' % { packages_per_page: @packages_per_page } - ) - @jobs = jobs.first(@packages_per_page) - - filename = "#{base}/index.html" - expand_template(:status_failing, filename) - end - - def generate_status_failing_always_failing(jobs, base) - @title = status_failing_title('Always failing') - @jobs = jobs.select { |j| j.always_failing? } - - filename = "#{base}/always_failing/index.html" - expand_template(:status_failing, filename) - end - - def generate_status_failing_had_success(jobs, base) - @title = status_failing_title('Had success') - @jobs = jobs.select { |j| j.had_success? } - - filename = "#{base}/had_success/index.html" - expand_template(:status_failing, filename) - end end end diff --git a/lib/debci/html/templates/job_listing.erb b/lib/debci/html/templates/job_listing.erb index a976ede679365b4468e8050da10e218fd9f98755..0cd1e4d243e00b82c27bf6b2f35d79eb8fc24483 100644 --- a/lib/debci/html/templates/job_listing.erb +++ b/lib/debci/html/templates/job_listing.erb @@ -82,18 +82,20 @@ <a href="/user/:user/retry/<%= job.run_id %>" ><i class='fa fa-recycle'></i></a> </td> <% end %> - <td><a href="/user/<%= job.requestor.username %>/jobs?package=<%= @package.name %>&suite[]=<%= @suite %>&arch[]=<%= @architecture %>"><%= job.requestor.username %></a></td> + <% if fields.include?(:requestor) %> + <td><a href="/user/<%= job.requestor.username %>/jobs?package=<%= job.package.name %>&suite[]=<%= job.suite %>&arch[]=<%= job.arch %>"><%= job.requestor.username %></a></td> + <% end %> <% package_dir = [job.suite, job.arch, job.package.prefix, job.package.name].join('/') %> - <% if fields.include?(:results) %> - <% if @artifacts_url_base %> - <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= job.run_id %>/log.gz">test log</a></td> - <td><a href="<%= @artifacts_url_base %>/<%= @package_dir %>/<%= job.run_id %>/artifacts.tar.gz">artifacts</a></td> + <% if fields.include?(:results) %> + <% if Debci.config.artifacts_url_base %> + <td><a href="<%= Debci.config.artifacts_url_base%>/<%= package_dir %>/<%= job.run_id %>/log.gz">test log</a></td> + <td><a href="<%= Debci.config.artifacts_url_base %>/<%= package_dir %>/<%= job.run_id %>/artifacts.tar.gz">artifacts</a></td> <% else %> <% if job.expired? %> <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td> <td><span class='fa fa-trash' title='file has been removed due to data retention policy'></span></td> <% else %> - <% dirname = File.join(Debci.config.data_basedir, 'autopkgtest', @package_dir, job.run_id.to_s) %> + <% dirname = File.join(Debci.config.data_basedir, 'autopkgtest', package_dir, job.run_id.to_s) %> <td> <%== filesize(File.join(dirname,'log.gz'),"<a href=\"/data/autopkgtest/#{package_dir}/#{job.run_id}/log.gz\">test log</a> <small>(%s)</small>")%> </td> @@ -105,7 +107,7 @@ <% end %> <% if fields.include?(:requested) %> <td><%= job.created_at %> | <%= job.time %></td> - <% end %> + <% end %> </tr> <% end %> </table> \ No newline at end of file diff --git a/lib/debci/html/templates/platform_specific_issues.erb b/lib/debci/html/templates/platform_specific_issues.erb index ac4115e3923d1229baf094a2c9afb8864b23af46..cbb77f6426eb3cf5c92f27986edbb8fc259753b3 100644 --- a/lib/debci/html/templates/platform_specific_issues.erb +++ b/lib/debci/html/templates/platform_specific_issues.erb @@ -1,13 +1,7 @@ <div class="row"> <div class="col-md-12"> <h1 class='page-header'>Status <small>/ Platform-Specific issues</small></h1> - <%== @status_nav %> - - <ol id='platform-specific-links' class='breadcrumb'> - <% @filters.each do |filter, data| %> - <li><a href='/<%= filter %>/'><%= data[0] %></a></li> - <% end %> - </ol> + <%== erb(:status_nav ) %> <table class='table table-striped'> <tr> diff --git a/lib/debci/html/templates/reject_list.erb b/lib/debci/html/templates/reject_list.erb index d2c22390ea6bdb8173c82441578fbc99ff164e03..f214924058f76ecc6296cff3d41ac23076af2289 100644 --- a/lib/debci/html/templates/reject_list.erb +++ b/lib/debci/html/templates/reject_list.erb @@ -1,7 +1,7 @@ <div class="row"> <div class="col-md-12"> <h1 class='page-header'>Status <small>/ RejectList</small></h1> - <%== @status_nav %> + <%== erb(:status_nav ) %> <table class='table table-striped'> <thead> <tr> @@ -44,4 +44,4 @@ </tbody> </table> </div> -</div> +</div> \ No newline at end of file diff --git a/lib/debci/html/templates/status.erb b/lib/debci/html/templates/status.erb index ba664c40daf4d9a3c93355eeea0b990177a6c6eb..f440a367508066f49f6120b7f54db97f91161b6c 100644 --- a/lib/debci/html/templates/status.erb +++ b/lib/debci/html/templates/status.erb @@ -2,7 +2,7 @@ <div class="col-md-12"> <h1 class='page-header'>Status <small>/ Charts</small></h1> - <%== @status_nav %> + <%== erb(:status_nav ) %> <div id='status'> <% Debci.config.arch_list.each do |arch| %> diff --git a/lib/debci/html/templates/status_alerts.erb b/lib/debci/html/templates/status_alerts.erb index c241a5b31eef448c6d3dd4bf11e391b11bb305b8..5692a3ed3454a65b077a1a8cb7111580cf2c4529 100644 --- a/lib/debci/html/templates/status_alerts.erb +++ b/lib/debci/html/templates/status_alerts.erb @@ -1,37 +1,10 @@ <div class='row'> <div class='col-md-12'> <h1 class='page-header'>Status <small>/ Alerts</small></h1> - <%== @status_nav %> + <%== erb(:status_nav ) %> <h4>There are currently <b><%= @alert_number %></b> packages with status alerts.</h4> - - <% if not @tmpfail.empty? %> - <table class='table table-striped'> - <tr> - <th>Package</th> - <th>Suite</th> - <th>Architecture</th> - <th>Status</th> - </tr> - - <% @tmpfail.each do |job| %> - <tr> - <td> - <a href="<%= package_url(job.package) %>"><%= job.package.name %></a> - </td> - <td> - <%= job.suite %> - </td> - <td> - <%= job.arch %> - </td> - <td> - <a href='<%= history_url(job)%>'/><%== icon(:tmpfail) %> <%= job.title %></a> - </td> - </tr> - <% end %> - </table> - <% end %> + <%== erb(:job_listing, locals: { jobs_list: @tmpfail ,fields: [:package, :suite, :arch, :status ]}) %> </div> <!-- class='col-md-12' --> </div> <!-- class='row' --> diff --git a/lib/debci/html/templates/status_failing.erb b/lib/debci/html/templates/status_failing.erb index 517e10ebfeee5082e32a541234884016fb79586e..bd1c162d2b427d8c36b40d2260e07aeb8cb78cea 100644 --- a/lib/debci/html/templates/status_failing.erb +++ b/lib/debci/html/templates/status_failing.erb @@ -1,35 +1,8 @@ <div class='row'> <div class='col-md-12'> <h1 class='page-header'>Status <small> / Failing / <%= @title %></small></h1> - <%== @status_nav %> - <ol id='failing-nav' class='breadcrumb'> - <li class='<%= "#{'active' if @suite.nil?}" %>'> - <span class='dropdown'> - <a href='#' class='dropdown-toggle' data-toggle='dropdown'>All</a> - <ul class='dropdown-menu'> - <li><a href='/status/failing'>Last <%= @packages_per_page %> Packages</a></li> - <li><a href='/status/failing/always_failing/'>Always Failing</a></li> - <li><a href='/status/failing/had_success/'>Had Success</a></li> - <li><a href='/status/failing/all/'>All Packages</a></li> - </ul> - </span> - </li> - - <% Debci.config.suite_list.each do |suite| %> - <li class='<%= "#{'active' if suite == @suite}" %>'> - <span class='dropdown'> - <a href='#' class='dropdown-toggle' data-toggle='dropdown'><%= suite %></a> - <ul class='dropdown-menu'> - <li><a href='/status/failing/<%= suite %>/'>Last <%= @packages_per_page %> Packages</a></li> - <li><a href='/status/failing/<%= suite %>/always_failing/'>Always Failing</a></li> - <li><a href='/status/failing/<%= suite %>/had_success/'>Had Success</a></li> - <li><a href='/status/failing/<%= suite %>/all/'>All Packages</a></li> - </ul> - </span> - </li> - <% end %> - </ol> + <%== erb(:status_nav ) %> <h4> <%= @jobs.length %> failures @@ -37,42 +10,7 @@ <div class='form-group'> <span>Enter Package Name: </span><input type='text' id='filter'> </div> - - <table id='failing-table' class='table table-striped'> - <thead> - <tr id='headline' class=''> - <th>Package</th> - <th>Suite</th> - <th>Architecture</th> - <th>Status</th> - </tr> - </thead> - <tbody> - <% @jobs.each do |job| %> - <tr> - <td> - <a href="<%= package_url(job.package) %>" class='package'> - <%= job.package.name %> - </a> - </td> - <td> - <%= job.suite %> - </td> - - <td> - <%= job.arch %> - </td> - - <td> - <a href='<%= history_url(job) %>'> - <%== icon(job.status) %> - <%= job.title %> - </a> - </td> - </tr> - <% end %> - </tbody> - </table> + <%== erb(:job_listing, locals: { jobs_list: @jobs, fields: [:package, :suite, :arch, :status ]}) %> </div> </div> diff --git a/lib/debci/html/templates/status_nav.erb b/lib/debci/html/templates/status_nav.erb index dce29bd17a7466a3bfee2b18787654b0c9145bad..f8314992643728b09d74e9c3b8fb82b5f7ba1bda 100644 --- a/lib/debci/html/templates/status_nav.erb +++ b/lib/debci/html/templates/status_nav.erb @@ -2,7 +2,7 @@ <li><a href='/status' ><i class='fa fa-area-chart' ></i> Status charts</a ></li> <li><a href='/status/alerts' ><i class='fa fa-exclamation-triangle'></i> Status alerts</a></li> <li><a href='/status/failing/' ><i class='fa fa-times' ></i> Status failing</a></li> - <li><a href='/status/pending' ><i class='fa fa-question-circle' ></i> Pending jobs</a></li> + <li><a href='/status/pending/' ><i class='fa fa-question-circle' ></i> Pending jobs</a></li> <li><a href='/status/reject_list/' ><i class='fa fa-hand-paper-o' ></i> RejectList</a></li> <li><a href='/status/platform-specific-issues/' ><i class='fa fa-eye' ></i> Platform-specific issues</a></li> <li><a href='/status/slow/' ><i class='fa fa-clock-o' ></i> Slow running tests</a></li> diff --git a/lib/debci/html/templates/status_pending_jobs.erb b/lib/debci/html/templates/status_pending_jobs.erb index e2bfaece9d09d5187794b4b44f8518286a4de0f4..411aaff05a1abe6a9696be4f82316aff90bc8a52 100644 --- a/lib/debci/html/templates/status_pending_jobs.erb +++ b/lib/debci/html/templates/status_pending_jobs.erb @@ -1,68 +1,10 @@ <div class='row'> <div class='col-md-12'> <h1 class='page-header'>Status <small>/ Pending Jobs</small></h1> - <%== @status_nav %> - - <ol id='pending-nav' class='breadcrumb'> - <li class='<%= "#{'active' if @current_page == 'status/pending'}" %>'> - <a href='/status/pending/'>Latest <%= @status_per_page %> Jobs</a> - </li> - <li class='<%= "#{'active' if @current_page == 'status/pending/all'}" %>'> - <a href='/status/pending/all/'> - All <span class='badge badge-pill'><%= @pending_jobs %></span> - </a></li> - - <% @suites_jobs.each do |suite, jobs| %> - <li class='<%= "#{'active' if @current_page.include?(suite)}" %>'> - <span class='dropdown'> - <a href='#' class='dropdown-toggle' data-toggle='dropdown'> - <%= suite %> <span class='badge badge-pill'><%= jobs %></span> - <b class='caret'></b> - </a> - <ul class='dropdown-menu'> - <li><a href='/<%= "status/pending/#{suite}/" %>'>Latest <%= @status_per_page %> Jobs</a></li> - <li><a href='/<%= "status/pending/#{suite}/all/" %>'>All Jobs</a></li> - </ul> - </span> - </li> - <% end %> - - </ol> + <%== erb(:status_nav ) %> <% if not @pending.empty? %> - <table class='table'> - <tr> - <th>Package</th> - <th>Suite</th> - <th>Architecture</th> - <th>Requestor</th> - <th>Trigger</th> - <th>Requested</th> - </tr> - - <% @pending.each do |job| %> - <tr> - <td> - <a class='pending' href='/packages/<%= job.package.prefix %>/<%= job.package.name %>/<%= job.suite %>/<%= job.arch%>/'><%= job.package.name %></a> - </td> - <td> - <a class='pending' href='/packages/<%= job.package.prefix %>/<%= job.package.name %>/<%= job.suite %>/<%= job.arch%>/'><%= job.suite %></a> - </td> - <td> - <a class='pending' href='/packages/<%= job.package.prefix %>/<%= job.package.name %>/<%= job.suite %>/<%= job.arch%>/'><%= job.arch %></a> - </td> - <td> - <a href="/user/<%= job.requestor.username %>/jobs?package=<%= job.package.name %>&suite[]=<%= job.suite %>&arch[]=<%= job.arch %>"><%= job.requestor.username %></a> - </td> - <td> - <%= h job.trigger %></a> - </td> - <td> - <%= job.created_at %> | <%= job.time %></a> - </td> - </tr> - <% end %> - </table> + <%== erb(:job_listing, locals: { jobs_list:@pending, fields: [:package, :suite, :arch, :requestor, :trigger, :requested ]}) %> <% end %> </div> <!-- class='col-md-12' --> diff --git a/lib/debci/html/templates/status_slow.erb b/lib/debci/html/templates/status_slow.erb index 18354c51284ddcfcf3f49ce12edeac0a473bd490..94c683cfc941ffad52d8e4e980b500f036ce887d 100644 --- a/lib/debci/html/templates/status_slow.erb +++ b/lib/debci/html/templates/status_slow.erb @@ -1,50 +1,12 @@ <div class='row'> <div class='col-md-12'> <h1 class='page-header'>Status <small>/ Slow running tests</small></h1> - <%== @status_nav %> + <%== erb(:status_nav ) %> <% if @slow.empty? %> <em>No items</em> <% else %> - <table class='table table-striped'> - <tr> - <th>Package</th> - <th>Version</th> - <th>Suite</th> - <th>Architecture</th> - <th>Status</th> - <th>Test time</th> - </tr> - - <% @slow.each do |status| %> - <% link = history_url(status) %> - <tr> - <td> - <a href="<%= link %>"><%= status.package.name %></a> - </td> - - <td> - <a href="<%= link %>"><%= status.version %></a> - </td> - - <td> - <a href="<%= link %>"><%= status.suite %></a> - </td> - - <td> - <a href="<%= link %>"><%= status.arch %></a> - </td> - - <td> - <%== icon(status.status)%> <%= status.title %> - </td> - - <td> - <%= status.duration_human %> - </td> - </tr> - <% end %> - </table> + <%== erb(:job_listing, locals: { jobs_list: @slow, fields: [:package, :version, :suite, :arch, :status, :duration]}) %> <% end %> </div> <!-- class='col-md-12' --> diff --git a/lib/debci/status.rb b/lib/debci/status.rb new file mode 100644 index 0000000000000000000000000000000000000000..3fdb7b38a7ac878a814b2b5a5d4dec3068031ba5 --- /dev/null +++ b/lib/debci/status.rb @@ -0,0 +1,74 @@ +require "debci/app" +require 'debci/html_helpers' +require 'debci/graph' + +module Debci + class Status < Debci::App + include Debci::HTMLHelpers + set :views, "#{File.dirname(__FILE__)}/html/templates" + + get "/?" do + erb :status + end + + get "/alerts" do + @tmpfail = Debci::Job.tmpfail.visible + @alert_number = @tmpfail.length + + erb :status_alerts + end + + get "/failing/" do + @jobs = Debci::Job.fail + @packages_per_page = Debci.config.failing_packages_per_page + + erb :status_failing + end + + get "/pending/" do + @current_page = 'status/pending/all' + @pending = Debci::Job.pending + @status_per_page = Debci.config.pending_status_per_page.to_i + @suites_jobs = Hash[ + Debci.config.suite_list.map do |x| + [x, Debci::Job.pending.where(suite: x).count] + end + ] + + erb :status_pending_jobs + end + + get "/pending/:suite/" do + suite = params[:suite] + @current_page = 'status/pending/all' + @pending = Debci::Job.pending.where(suite: suite) + @pending_jobs = Debci::Job.pending.count + @status_per_page = Debci.config.pending_status_per_page.to_i + @suites_jobs = Hash[ + Debci.config.suite_list.map do |x| + [x, Debci::Job.pending.where(suite: x).count] + end + ] + + erb :status_pending_jobs + end + + get "/reject_list/" do + @reject_list = Debci.reject_list + + erb :reject_list + end + + get "/platform-specific-issues/" do + @issues = Debci::Job.platform_specific_issues + + erb :platform_specific_issues + end + + get "/slow/" do + @slow = Debci::Job.slow.sort_by { |j| j.package.name } + + erb :status_slow + end + end +end diff --git a/spec/debci/html_spec.rb b/spec/debci/html_spec.rb index 84de692caa3ede8f2a0708c76afc5df92f5588b1..42e70e1134da5fa3d489c3c41280b56a93f705cd 100644 --- a/spec/debci/html_spec.rb +++ b/spec/debci/html_spec.rb @@ -15,7 +15,6 @@ describe Debci::HTML do context 'generating global pages' do before(:each) { Debci::HTML.update } it('produces home page') { expect(html / 'index.html').to exist } - it('produces status page') { expect(html / 'status/index.html').to exist } end let(:package) { Debci::Package.create!(name: 'foobar') } @@ -76,20 +75,6 @@ describe Debci::HTML do end end - context 'producing status pages' do - let(:h) { Debci::HTML.new } - let(:reject_list_data) do - { "foobar" => { "*" => { "*" => { "*" => "" } } } } - end - it 'produces rejectlist page' do - allow_any_instance_of(Debci::RejectList).to receive(:data).and_return(reject_list_data) - h.reject_list - - page = html / 'status/reject_list/index.html' - expect(page).to exist - end - end - context 'package pages' do before(:each) do Debci::HTML.update_package(job.package) diff --git a/spec/debci/status_spec.rb b/spec/debci/status_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..d61fbe6153606a8757d2c62c9430684b41d9d1ba --- /dev/null +++ b/spec/debci/status_spec.rb @@ -0,0 +1,79 @@ +require "spec_helper" +require 'spec_mock_server' +require 'debci' +require 'debci/html' +require 'debci/status' +require 'rack/test' +require 'json' +require 'debci/job' + +describe Debci::Status do + include Rack::Test::Methods + + class Status < Debci::Status + set :raise_errors, true + set :show_exceptions, false + end + + def app + mock_server('/status', Status) + end + + context 'showing status page' do + it 'works' do + Debci::HTML.update # generate graphs + get "/status" + expect(last_response.body).to match(/status/) + expect(last_response.status).to eq(200) + end + end + let(:theuser) { Debci::User.create!(username: 'debci') } + + context 'showing status alerts page' do + it 'lists tmpfail jobs' do + pkg = Debci::Package.create!(name: 'mypackage') + Debci::Job.create!(package: pkg, suite: 'unstable', arch: arch, status: 'tmpfail', requestor: theuser, date: Time.now) + get '/status/alerts' + expect(last_response.body).to match('mypackage') + end + end + + context 'showing status failing page' do + it 'lists fail jobs' do + pkg = Debci::Package.create!(name: 'mypackage') + Debci::Job.create!(package: pkg, suite: 'unstable', arch: arch, status: 'fail', requestor: theuser, date: Time.now) + get '/status/failing/' + expect(last_response.body).to match('mypackage') + end + end + + context 'showing status pending page' do + it 'lists pending jobs' do + pkg = Debci::Package.create!(name: 'mypackage') + yesterday = Time.now - 1.day + Debci::Job.create!(package: pkg, suite: 'unstable', arch: arch, status: nil, requestor: theuser, trigger: 'migration', created_at: yesterday) + get "/status/pending/" + expect(last_response.body).to match('mypackage') + end + end + + context 'showing platform specific issues page' do + it 'lists platform specific issues jobs' do + pkg = Debci::Package.create!(name: 'mypackage') + allow(Debci.config).to receive(:arch_list).and_return(['amd64', 'arm64']) + Debci::Job.create!(package: pkg, suite: 'unstable', status: 'pass', arch: 'amd64', requestor: theuser, date: Time.now) + Debci::Job.create!(package: pkg, suite: 'unstable', status: 'fail', arch: 'arm64', requestor: theuser, date: Time.now) + get '/status/platform-specific-issues/' + expect(last_response.body).to match('mypackage') + end + end + + context 'showing slow page' do + it 'lists slow jobs' do + pkg = Debci::Package.create!(name: 'mypackage') + Debci::Job.create!(package: pkg, suite: 'unstable', arch: arch, status: 'pass', duration_seconds: 4000, requestor: theuser, date: '2019-02-03 11:00') + get '/status/slow/' + expect(last_response.body).to match('mypackage') + end + end +end