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

base_attachment_service_spec.rb « hashed_storage « projects « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4834af792254f923680fab0f402c6ccc6d0b3ce0 (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
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::HashedStorage::BaseAttachmentService, feature_category: :groups_and_projects do
  let(:project) { create(:project, :repository, storage_version: 0, skip_disk_validation: true) }

  subject(:service) { described_class.new(project: project, old_disk_path: project.full_path, logger: nil) }

  describe '#old_disk_path' do
    it { is_expected.to respond_to :old_disk_path }
  end

  describe '#new_disk_path' do
    it { is_expected.to respond_to :new_disk_path }
  end

  describe '#skipped?' do
    it { is_expected.to respond_to :skipped? }
  end

  describe '#target_path_discardable?' do
    it 'returns false' do
      expect(subject.target_path_discardable?('something/something')).to be_falsey
    end
  end

  describe '#discard_path!' do
    it 'renames target path adding a timestamp at the end' do
      target_path = Dir.mktmpdir
      expect(Dir.exist?(target_path)).to be_truthy

      freeze_time do
        suffix = Time.current.utc.to_i
        subject.send(:discard_path!, target_path)

        expected_renamed_path = "#{target_path}-#{suffix}"

        expect(Dir.exist?(target_path)).to be_falsey
        expect(Dir.exist?(expected_renamed_path)).to be_truthy
      end
    end
  end

  describe '#move_folder!' do
    context 'when old_path is not a directory' do
      it 'adds information to the logger and returns true' do
        Tempfile.create do |old_path|
          new_path = "#{old_path}-new"

          expect(subject.send(:move_folder!, old_path, new_path)).to be_truthy
        end
      end
    end
  end
end