From 871de0f18581bb03fed5c0d800f8183598a0195f Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 23 Nov 2017 16:57:27 +0100 Subject: Rename artifacts_* to legacy_artifacts_* --- spec/uploaders/legacy_artifact_uploader_spec.rb | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 spec/uploaders/legacy_artifact_uploader_spec.rb (limited to 'spec/uploaders/legacy_artifact_uploader_spec.rb') diff --git a/spec/uploaders/legacy_artifact_uploader_spec.rb b/spec/uploaders/legacy_artifact_uploader_spec.rb new file mode 100644 index 00000000000..1d9adaccd8d --- /dev/null +++ b/spec/uploaders/legacy_artifact_uploader_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +describe LegacyArtifactUploader do + set(:job) { create(:ci_build) } + let(:uploader) { described_class.new(job, :artifacts_file) } + let(:path) { Gitlab.config.artifacts.path } + + describe '.local_artifacts_store' do + subject { described_class.local_artifacts_store } + + it "delegate to artifacts path" do + expect(Gitlab.config.artifacts).to receive(:path) + + subject + end + end + + describe '.artifacts_upload_path' do + subject { described_class.artifacts_upload_path } + + it { is_expected.to start_with(path) } + it { is_expected.to end_with('tmp/uploads/') } + end + + describe '#store_dir' do + subject { uploader.store_dir } + + it { is_expected.to start_with(path) } + it { is_expected.to end_with("#{job.project_id}/#{job.id}") } + end + + describe '#cache_dir' do + subject { uploader.cache_dir } + + it { is_expected.to start_with(path) } + it { is_expected.to end_with('/tmp/cache') } + end + + describe '#work_dir' do + subject { uploader.work_dir } + + it { is_expected.to start_with(path) } + it { is_expected.to end_with('/tmp/work') } + end + + describe '#filename' do + # we need to use uploader, as this makes to use mounter + # which initialises uploader.file object + let(:uploader) { job.artifacts_file } + + subject { uploader.filename } + + it { is_expected.to be_nil } + + context 'with artifacts' do + let(:job) { create(:ci_build, :artifacts) } + + it { is_expected.not_to be_nil } + end + end +end -- cgit v1.2.3 From 38c61ab6df15fbd1eab22a8dff8da01b17c075f3 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 23 Nov 2017 18:51:20 +0100 Subject: Fix specs failures, and use factory with `:ci_job_artifact, :archive` --- spec/uploaders/legacy_artifact_uploader_spec.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'spec/uploaders/legacy_artifact_uploader_spec.rb') diff --git a/spec/uploaders/legacy_artifact_uploader_spec.rb b/spec/uploaders/legacy_artifact_uploader_spec.rb index 1d9adaccd8d..203630de91c 100644 --- a/spec/uploaders/legacy_artifact_uploader_spec.rb +++ b/spec/uploaders/legacy_artifact_uploader_spec.rb @@ -5,8 +5,8 @@ describe LegacyArtifactUploader do let(:uploader) { described_class.new(job, :artifacts_file) } let(:path) { Gitlab.config.artifacts.path } - describe '.local_artifacts_store' do - subject { described_class.local_artifacts_store } + describe '.local_store_path' do + subject { described_class.local_store_path } it "delegate to artifacts path" do expect(Gitlab.config.artifacts).to receive(:path) @@ -58,4 +58,22 @@ describe LegacyArtifactUploader do it { is_expected.not_to be_nil } end end + + context 'file is stored in valid path' do + let(:file) do + fixture_file_upload(Rails.root.join( + 'spec/fixtures/ci_build_artifacts.zip'), 'application/zip') + end + + before do + uploader.store!(file) + end + + subject { uploader.file.path } + + it { is_expected.to start_with(path) } + it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") } + it { is_expected.to include("/#{job.project_id.to_s}/") } + it { is_expected.to end_with("ci_build_artifacts.zip") } + end end -- cgit v1.2.3 From ee8efb3d67ba8b8b2ece9962cd2aa79063fffaa0 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 23 Nov 2017 19:41:49 +0100 Subject: Sync ArtifactUploader specs with EE --- spec/uploaders/legacy_artifact_uploader_spec.rb | 28 ++++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'spec/uploaders/legacy_artifact_uploader_spec.rb') diff --git a/spec/uploaders/legacy_artifact_uploader_spec.rb b/spec/uploaders/legacy_artifact_uploader_spec.rb index 203630de91c..714976b92c1 100644 --- a/spec/uploaders/legacy_artifact_uploader_spec.rb +++ b/spec/uploaders/legacy_artifact_uploader_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' describe LegacyArtifactUploader do - set(:job) { create(:ci_build) } - let(:uploader) { described_class.new(job, :artifacts_file) } - let(:path) { Gitlab.config.artifacts.path } + let(:job) { create(:ci_build) } + let(:uploader) { described_class.new(job, :legacy_artifacts_file) } + let(:local_path) { Gitlab.config.artifacts.path } describe '.local_store_path' do subject { described_class.local_store_path } @@ -18,28 +18,32 @@ describe LegacyArtifactUploader do describe '.artifacts_upload_path' do subject { described_class.artifacts_upload_path } - it { is_expected.to start_with(path) } + it { is_expected.to start_with(local_path) } it { is_expected.to end_with('tmp/uploads/') } end describe '#store_dir' do subject { uploader.store_dir } - it { is_expected.to start_with(path) } - it { is_expected.to end_with("#{job.project_id}/#{job.id}") } + let(:path) { "#{job.created_at.utc.strftime('%Y_%m')}/#{job.project_id}/#{job.id}" } + + context 'when using local storage' do + it { is_expected.to start_with(local_path) } + it { is_expected.to end_with(path) } + end end describe '#cache_dir' do subject { uploader.cache_dir } - it { is_expected.to start_with(path) } + it { is_expected.to start_with(local_path) } it { is_expected.to end_with('/tmp/cache') } end describe '#work_dir' do subject { uploader.work_dir } - it { is_expected.to start_with(path) } + it { is_expected.to start_with(local_path) } it { is_expected.to end_with('/tmp/work') } end @@ -51,12 +55,6 @@ describe LegacyArtifactUploader do subject { uploader.filename } it { is_expected.to be_nil } - - context 'with artifacts' do - let(:job) { create(:ci_build, :artifacts) } - - it { is_expected.not_to be_nil } - end end context 'file is stored in valid path' do @@ -71,7 +69,7 @@ describe LegacyArtifactUploader do subject { uploader.file.path } - it { is_expected.to start_with(path) } + it { is_expected.to start_with(local_path) } it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") } it { is_expected.to include("/#{job.project_id.to_s}/") } it { is_expected.to end_with("ci_build_artifacts.zip") } -- cgit v1.2.3 From 6881d0917458f9b62542ee2908e2d258c75a8537 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 23 Nov 2017 19:53:31 +0100 Subject: Fix rubocop --- spec/uploaders/legacy_artifact_uploader_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/uploaders/legacy_artifact_uploader_spec.rb') diff --git a/spec/uploaders/legacy_artifact_uploader_spec.rb b/spec/uploaders/legacy_artifact_uploader_spec.rb index 714976b92c1..efeffb78772 100644 --- a/spec/uploaders/legacy_artifact_uploader_spec.rb +++ b/spec/uploaders/legacy_artifact_uploader_spec.rb @@ -59,8 +59,8 @@ describe LegacyArtifactUploader do context 'file is stored in valid path' do let(:file) do - fixture_file_upload(Rails.root.join( - 'spec/fixtures/ci_build_artifacts.zip'), 'application/zip') + fixture_file_upload( + Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), 'application/zip') end before do @@ -71,7 +71,7 @@ describe LegacyArtifactUploader do it { is_expected.to start_with(local_path) } it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") } - it { is_expected.to include("/#{job.project_id.to_s}/") } + it { is_expected.to include("/#{job.project_id}/") } it { is_expected.to end_with("ci_build_artifacts.zip") } end end -- cgit v1.2.3