Commit 8f1f73d4 authored by Shinya Maeda's avatar Shinya Maeda

Fix typo in spec. Add a test for the case of when trace is stored in database

parent 2184c753
...@@ -16,7 +16,7 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2 ...@@ -16,7 +16,7 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2
context 'when trace file exsits at the right place' do context 'when trace file exsits at the right place' do
before do before do
create_legacy_trace(@build, 'aiueo') create_legacy_trace(@build, 'trace in file')
end end
it 'correctly archive legacy traces' do it 'correctly archive legacy traces' do
...@@ -27,15 +27,33 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2 ...@@ -27,15 +27,33 @@ describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 2
expect(job_artifacts.count).to eq(1) expect(job_artifacts.count).to eq(1)
expect(File.exist?(legacy_trace_path(@build))).to be_falsy expect(File.exist?(legacy_trace_path(@build))).to be_falsy
expect(File.read(archived_trace_path(job_artifacts.first))).to eq('aiueo') expect(File.read(archived_trace_path(job_artifacts.first))).to eq('trace in file')
end end
end end
context 'when trace file does not exsits at the right place' do context 'when trace file does not exsits at the right place' do
it 'does not raise errors and create job artifact row' do it 'does not raise errors nor create job artifact' do
described_class.new.perform(1, 1) expect { described_class.new.perform(1, 1) }.not_to raise_error
expect(job_artifacts.count).to eq(0) expect(job_artifacts.count).to eq(0)
end end
end end
context 'when trace data exsits in database' do
before do
create_legacy_trace_in_db(@build, 'trace in db')
end
it 'correctly archive legacy traces' do
expect(job_artifacts.count).to eq(0)
expect(@build.read_attribute(:trace)).not_to be_empty
described_class.new.perform(1, 1)
@build.reload
expect(job_artifacts.count).to eq(1)
expect(@build.read_attribute(:trace)).to be_nil
expect(File.read(archived_trace_path(job_artifacts.first))).to eq('trace in db')
end
end
end end
...@@ -3,6 +3,10 @@ module TraceHelpers ...@@ -3,6 +3,10 @@ module TraceHelpers
File.open(legacy_trace_path(build), 'wb') { |stream| stream.write(content) } File.open(legacy_trace_path(build), 'wb') { |stream| stream.write(content) }
end end
def create_legacy_trace_in_db(build, content)
build.update_column(:trace, content)
end
def legacy_trace_path(build) def legacy_trace_path(build)
legacy_trace_dir = File.join(Settings.gitlab_ci.builds_path, legacy_trace_dir = File.join(Settings.gitlab_ci.builds_path,
build.created_at.utc.strftime("%Y_%m"), build.created_at.utc.strftime("%Y_%m"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment