diff options
Diffstat (limited to 'spec/uploaders')
-rw-r--r-- | spec/uploaders/job_artifact_uploader_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/uploaders/job_artifact_uploader_spec.rb b/spec/uploaders/job_artifact_uploader_spec.rb index 3ad5fe7e3b3..061432f082a 100644 --- a/spec/uploaders/job_artifact_uploader_spec.rb +++ b/spec/uploaders/job_artifact_uploader_spec.rb @@ -40,6 +40,53 @@ describe JobArtifactUploader do it { is_expected.to end_with("ci_build_artifacts.zip") } end + describe '#dynamic_segment' do + let(:uploaded_content) { File.binread(Rails.root + 'spec/fixtures/ci_build_artifacts.zip') } + let(:model) { uploader.model } + + shared_examples_for 'Read file from legacy path' do + it 'store_path returns the legacy path' do + expect(model.file.store_path).to eq(File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.job_id.to_s, 'ci_build_artifacts.zip')) + end + + it 'has exactly the same content' do + expect(::File.binread(model.file.path)).to eq(uploaded_content) + end + end + + shared_examples_for 'Read file from hashed path' do + it 'store_path returns hashed path' do + expect(model.file.store_path).to eq(File.join(disk_hash[0..1], disk_hash[2..3], disk_hash, creation_date, model.job_id.to_s, model.id.to_s, 'ci_build_artifacts.zip')) + end + + it 'has exactly the same content' do + expect(::File.binread(model.file.path)).to eq(uploaded_content) + end + end + + context 'when a job artifact is stored in legacy_path' do + let(:job_artifact) { create(:ci_job_artifact, :legacy_archive) } + + it_behaves_like 'Read file from legacy path' + end + + context 'when the artifact file is stored in hashed_path' do + let(:job_artifact) { create(:ci_job_artifact, :archive) } + let(:disk_hash) { Digest::SHA2.hexdigest(model.project_id.to_s) } + let(:creation_date) { model.created_at.utc.strftime('%Y_%m_%d') } + + it_behaves_like 'Read file from hashed path' + + context 'when file_location column is empty' do + before do + job_artifact.update_column(:file_location, nil) + end + + it_behaves_like 'Read file from hashed path' + end + end + end + describe "#migrate!" do before do uploader.store!(fixture_file_upload('spec/fixtures/trace/sample_trace')) |