summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/bare_repository_import/repository_spec.rb
blob: a07c53711344fe8f8725cf1d0fda1b44eddaa864 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require 'spec_helper'

describe ::Gitlab::BareRepositoryImport::Repository do
  context 'legacy storage' do
    subject { described_class.new('/full/path/', '/full/path/to/repo.git') }

    it 'stores the repo path' do
      expect(subject.repo_path).to eq('/full/path/to/repo.git')
    end

    it 'stores the group path' do
      expect(subject.group_path).to eq('to')
    end

    it 'stores the project name' do
      expect(subject.project_name).to eq('repo')
    end

    it 'stores the wiki path' do
      expect(subject.wiki_path).to eq('/full/path/to/repo.wiki.git')
    end

    describe '#processable?' do
      it 'returns false if it is a wiki' do
        subject = described_class.new('/full/path/', '/full/path/to/a/b/my.wiki.git')

        expect(subject).not_to be_processable
      end

      it 'returns true if group path is missing' do
        subject = described_class.new('/full/path/', '/full/path/repo.git')

        expect(subject).to be_processable
      end

      it 'returns true when group path and project name are present' do
        expect(subject).to be_processable
      end
    end

    describe '#project_full_path' do
      it 'returns the project full path with trailing slash in the root path' do
        expect(subject.project_full_path).to eq('to/repo')
      end

      it 'returns the project full path with no trailing slash in the root path' do
        subject = described_class.new('/full/path', '/full/path/to/repo.git')

        expect(subject.project_full_path).to eq('to/repo')
      end
    end
  end

  context 'hashed storage' do
    let(:gitlab_shell) { Gitlab::Shell.new }
    let(:repository_storage) { 'default' }
    let(:root_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
    let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
    let(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" }
    let(:repo_path) { File.join(root_path, "#{hashed_path}.git") }
    let(:wiki_path) { File.join(root_path, "#{hashed_path}.wiki.git") }

    before do
      gitlab_shell.create_repository(repository_storage, hashed_path, 'group/project')
      Gitlab::GitalyClient::StorageSettings.allow_disk_access do
        repository = Rugged::Repository.new(repo_path)
        repository.config['gitlab.fullpath'] = 'to/repo'
      end
    end

    after do
      gitlab_shell.remove_repository(repository_storage, hashed_path)
    end

    subject { described_class.new(root_path, repo_path) }

    it 'stores the repo path' do
      expect(subject.repo_path).to eq(repo_path)
    end

    it 'stores the wiki path' do
      expect(subject.wiki_path).to eq(wiki_path)
    end

    it 'reads the group path from .git/config' do
      expect(subject.group_path).to eq('to')
    end

    it 'reads the project name from .git/config' do
      expect(subject.project_name).to eq('repo')
    end

    describe '#processable?' do
      it 'returns false if it is a wiki' do
        subject = described_class.new(root_path, wiki_path)

        expect(subject).not_to be_processable
      end

      it 'returns false when group and project name are missing' do
        repository = Rugged::Repository.new(repo_path)
        repository.config.delete('gitlab.fullpath')

        expect(subject).not_to be_processable
      end

      it 'returns true when group path and project name are present' do
        expect(subject).to be_processable
      end
    end

    describe '#project_full_path' do
      it 'returns the project full path with trailing slash in the root path' do
        expect(subject.project_full_path).to eq('to/repo')
      end

      it 'returns the project full path with no trailing slash in the root path' do
        subject = described_class.new(root_path[0...-1], repo_path)

        expect(subject.project_full_path).to eq('to/repo')
      end
    end
  end
end