Skip to content

Commit 430c3da

Browse files
committed
Add a regression test for report
We're about to refactor the BLAST::Report class, and it does not seem to have any unit tests. The implementation is a bit hard to comprehend with generic abbreviated variable names and data accessed via indexes. To aid the refactoring, create a regression test that takes a job generated on current master as gold standard and compares it with the live version. If refactoring changes the outputs, the test will fail.
1 parent 4abd19d commit 430c3da

8 files changed

Lines changed: 16972 additions & 0 deletions

File tree

spec/blast/report_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'spec_helper'
2+
require 'sequenceserver/report'
3+
require 'sequenceserver/blast/report'
4+
5+
module SequenceServer
6+
RSpec.describe BLAST::Job do
7+
before do
8+
FileUtils.mkdir_p(DOTDIR)
9+
FileUtils.rm_r(File.join(DOTDIR, job_id)) if File.exist?(File.join(DOTDIR, job_id))
10+
FileUtils.cp_r(File.join(__dir__, '..', 'fixtures', job_id), DOTDIR)
11+
12+
# For all files in DOTDIR/job_id, replace $PATH_PREFIX with the root dir of the project.
13+
job_dir = File.join(DOTDIR, job_id)
14+
root_dir = File.expand_path(File.join(__dir__, '..', '..', '..'))
15+
Dir[File.join(job_dir, '**', '*')].each do |f|
16+
File.write(f, File.read(f).gsub('$PATH_PREFIX', root_dir)) if File.file?(f)
17+
end
18+
19+
SequenceServer.init
20+
end
21+
22+
let(:job_id) { '38334a72-e8e7-4732-872b-24d3f8723563' }
23+
let(:job) { SequenceServer::Job.fetch(job_id) }
24+
let(:report) { BLAST::Report.new(job) }
25+
let(:keys_to_ignore) { %i[querydb submitted_at imported_xml seqserv_version cloud_sharing_enabled] }
26+
27+
describe "#to_json" do
28+
it "returns a JSON representation of the job" do
29+
actual_report = JSON.parse(report.to_json).reject { |k, _| keys_to_ignore.include?(k) }
30+
expected_report = JSON.parse(File.read(File.join(job.dir, 'expected_outputs/frontend.json'))).reject { |k, _| keys_to_ignore.include?(k) }
31+
32+
actual_report.each do |k, v|
33+
expect(v).to eq(expected_report[k])
34+
end
35+
end
36+
end
37+
end
38+
end

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/expected_outputs/frontend.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/expected_outputs/sequenceserver-custom_tsv_report.tsv

Lines changed: 443 additions & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/expected_outputs/sequenceserver-xml_report.xml

Lines changed: 4143 additions & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/job.yaml

Lines changed: 1027 additions & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/query.fa

Lines changed: 931 additions & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/38334a72-e8e7-4732-872b-24d3f8723563/stderr

Whitespace-only changes.

0 commit comments

Comments
 (0)