Raise an error if conditions are not fulfilled in archive method
This commit is contained in:
parent
9ca8a5d43f
commit
91117452e1
2 changed files with 16 additions and 4 deletions
|
@ -94,7 +94,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
def archive!
|
||||
return if trace_artifact
|
||||
raise 'Already archived' if trace_artifact
|
||||
raise 'Job is not finished yet' unless job.complete?
|
||||
|
||||
if current_path
|
||||
File.open(current_path) do |stream|
|
||||
|
|
|
@ -455,7 +455,7 @@ describe Gitlab::Ci::Trace do
|
|||
|
||||
context 'when job does not have trace artifact' do
|
||||
context 'when trace file stored in default path' do
|
||||
let!(:build) { create(:ci_build, :trace_live) }
|
||||
let!(:build) { create(:ci_build, :success, :trace_live) }
|
||||
let!(:src_path) { trace.read { |s| return s.path } }
|
||||
let!(:src_checksum) { Digest::SHA256.file(src_path).digest }
|
||||
|
||||
|
@ -481,7 +481,8 @@ describe Gitlab::Ci::Trace do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when trace stored in database' do
|
||||
context 'when trace is stored in database' do
|
||||
let(:build) { create(:ci_build, :success) }
|
||||
let(:trace_content) { IO.read(expand_fixture_path('trace/sample_trace')) }
|
||||
let!(:src_checksum) { Digest::SHA256.digest(trace_content) }
|
||||
|
||||
|
@ -519,9 +520,19 @@ describe Gitlab::Ci::Trace do
|
|||
|
||||
it 'does not archive' do
|
||||
expect_any_instance_of(Gitlab::Ci::Trace).not_to receive(:archive_stream!)
|
||||
expect { subject }.not_to change { Ci::JobArtifact.count }
|
||||
expect { subject }.to raise_error('Already archived')
|
||||
expect(build.job_artifacts_trace.file.exists?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'when job is not finished yet' do
|
||||
let!(:build) { create(:ci_build, :running, :trace_live) }
|
||||
|
||||
it 'does not archive' do
|
||||
expect_any_instance_of(Gitlab::Ci::Trace).not_to receive(:archive_stream!)
|
||||
expect { subject }.to raise_error('Job is not finished yet')
|
||||
expect(build.trace.exist?).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue