repository_spec.rb 3.7 KB
Newer Older
1 2 3
require 'spec_helper'

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

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

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

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

19 20 21 22 23 24 25
    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')
26

27
        expect(subject).not_to be_processable
28
      end
29

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

33
        expect(subject).to be_processable
34 35 36
      end

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

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

46 47
      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')
48

49
        expect(subject.project_full_path).to eq('to/repo')
50
      end
51 52 53
    end
  end

54 55 56 57 58 59 60 61
  context 'hashed storage' do
    let(:gitlab_shell) { Gitlab::Shell.new }
    let(:repository_storage) { 'default' }
    let(:root_path) { Gitlab.config.repositories.storages[repository_storage]['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") }
62

63 64 65 66
    before do
      gitlab_shell.add_repository(repository_storage, hashed_path)
      repository = Rugged::Repository.new(repo_path)
      repository.config['gitlab.fullpath'] = 'to/repo'
67 68
    end

69 70
    after do
      gitlab_shell.remove_repository(root_path, hashed_path)
71 72
    end

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    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')
89 90
    end

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

95
        expect(subject).not_to be_processable
96 97 98 99 100 101
      end

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

102
        expect(subject).not_to be_processable
103 104
      end

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

110
    describe '#project_full_path' do
111 112 113 114 115 116 117
      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)

118 119
        expect(subject.project_full_path).to eq('to/repo')
      end
120 121 122
    end
  end
end