Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/ci/job_artifact_spec.rb')
-rw-r--r--spec/models/ci/job_artifact_spec.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index 83c233fa942..498af80dbb6 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -824,4 +824,82 @@ RSpec.describe Ci::JobArtifact, feature_category: :build_artifacts do
it { is_expected.to eq(artifact.file.filename) }
end
+
+ describe '#to_deleted_object_attrs' do
+ let(:pick_up_at) { nil }
+ let(:expire_at) { nil }
+ let(:file_final_path) { nil }
+
+ let(:artifact) do
+ create(
+ :ci_job_artifact,
+ :archive,
+ :remote_store,
+ file_final_path: file_final_path,
+ expire_at: expire_at
+ )
+ end
+
+ subject(:attributes) { artifact.to_deleted_object_attrs(pick_up_at) }
+
+ before do
+ stub_artifacts_object_storage
+ end
+
+ shared_examples_for 'returning attributes for object deletion' do
+ it 'returns the file store' do
+ expect(attributes[:file_store]).to eq(artifact.file_store)
+ end
+
+ context 'when pick_up_at is present' do
+ let(:pick_up_at) { 2.hours.ago }
+
+ it 'returns the pick_up_at value' do
+ expect(attributes[:pick_up_at]).to eq(pick_up_at)
+ end
+ end
+
+ context 'when pick_up_at is not present' do
+ context 'and expire_at is present' do
+ let(:expire_at) { 4.hours.ago }
+
+ it 'sets expire_at as pick_up_at' do
+ expect(attributes[:pick_up_at]).to eq(expire_at)
+ end
+ end
+
+ context 'and expire_at is not present' do
+ it 'sets current time as pick_up_at' do
+ freeze_time do
+ expect(attributes[:pick_up_at]).to eq(Time.current)
+ end
+ end
+ end
+ end
+ end
+
+ context 'when file_final_path is present' do
+ let(:file_final_path) { 'some/hash/path/to/randomfile' }
+
+ it 'returns the store_dir and file based on the file_final_path' do
+ expect(attributes).to include(
+ store_dir: 'some/hash/path/to',
+ file: 'randomfile'
+ )
+ end
+
+ it_behaves_like 'returning attributes for object deletion'
+ end
+
+ context 'when file_final_path is not present' do
+ it 'returns the uploader default store_dir and file_identifier' do
+ expect(attributes).to include(
+ store_dir: artifact.file.store_dir.to_s,
+ file: artifact.file_identifier
+ )
+ end
+
+ it_behaves_like 'returning attributes for object deletion'
+ end
+ end
end