diff options
Diffstat (limited to 'spec/support/shared_examples/ci_trace_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/ci_trace_shared_examples.rb | 106 |
1 files changed, 104 insertions, 2 deletions
diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb index db723a323f8..94e82b8ce90 100644 --- a/spec/support/shared_examples/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/ci_trace_shared_examples.rb @@ -138,6 +138,28 @@ shared_examples_for 'common trace features' do end end + describe '#write' do + subject { trace.send(:write, mode) { } } + + let(:mode) { 'wb' } + + context 'when arhicved trace does not exist yet' do + it 'does not raise an error' do + expect { subject }.not_to raise_error + end + end + + context 'when arhicved trace already exists' do + before do + create(:ci_job_artifact, :trace, job: build) + end + + it 'raises an error' do + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) + end + end + end + describe '#set' do before do trace.set("12") @@ -574,7 +596,7 @@ shared_examples_for 'trace with disabled live trace feature' do it 'does not archive' do expect_any_instance_of(described_class).not_to receive(:archive_stream!) - expect { subject }.to raise_error('Already archived') + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) expect(build.job_artifacts_trace.file.exists?).to be_truthy end end @@ -589,6 +611,55 @@ shared_examples_for 'trace with disabled live trace feature' do end end end + + describe '#erase!' do + subject { trace.erase! } + + context 'when it is a live trace' do + context 'when trace is stored in database' do + let(:build) { create(:ci_build) } + + before do + build.update_column(:trace, 'sample trace') + end + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + + context 'when trace is stored in file storage' do + let(:build) { create(:ci_build, :trace_live) } + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + end + + context 'when it is an archived trace' do + let(:build) { create(:ci_build, :trace_artifact) } + + it "has trace at first" do + expect(trace.raw).not_to be_nil + end + + it "removes trace" do + subject + + build.reload + expect(trace.raw).to be_nil + end + end + end end shared_examples_for 'trace with enabled live trace feature' do @@ -761,7 +832,7 @@ shared_examples_for 'trace with enabled live trace feature' do it 'does not archive' do expect_any_instance_of(described_class).not_to receive(:archive_stream!) - expect { subject }.to raise_error('Already archived') + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) expect(build.job_artifacts_trace.file.exists?).to be_truthy end end @@ -776,4 +847,35 @@ shared_examples_for 'trace with enabled live trace feature' do end end end + + describe '#erase!' do + subject { trace.erase! } + + context 'when it is a live trace' do + let(:build) { create(:ci_build, :trace_live) } + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + + context 'when it is an archived trace' do + let(:build) { create(:ci_build, :trace_artifact) } + + it "has trace at first" do + expect(trace.raw).not_to be_nil + end + + it "removes trace" do + subject + + build.reload + expect(trace.raw).to be_nil + end + end + end end |