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

delete_stored_artifacts_service_spec.rb « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 625f86d6074e019a9596a8fe94727c39ac1bdcc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

describe Ci::DeleteStoredArtifactsService do
  describe '#perform' do
    let(:project) { create(:project) }
    let(:service) { described_class.new(project) }

    subject { service.execute(artifact_store_path, local) }

    context 'with a local artifact' do
      let(:artifact_store_path) { 'local_file_path' }
      let(:local) { true }
      let(:full_path) { File.join(Gitlab.config.artifacts['storage_path'], 'local_file_path') }

      before do
        allow(File).to receive(:exist?).with(full_path).and_return(true)
      end

      it 'deletes the local artifact' do
        expect(File).to receive(:delete).with(full_path)

        subject
      end
    end

    context 'with a remote artifact' do
      let(:artifact_store_path) { 'remote_file_path' }
      let(:local) { false }
      let(:file_double) { double }

      before do
        stub_artifacts_object_storage

        allow_any_instance_of(Fog::AWS::Storage::Files).to receive(:new).with(key: 'remote_file_path').and_return(file_double)
      end

      it 'deletes the remote artifact' do
        expect(file_double).to receive(:destroy)

        subject
      end
    end
  end
end