blob: 1f2848a29e9183c1d0b3add9574c6bfd66c75383 (
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
|
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::SubmoduleLinks do
let(:submodule_item) { double(id: 'hash', path: 'gitlab-foss') }
let(:repo) { double }
let(:links) { described_class.new(repo) }
describe '#for' do
let(:ref) { 'ref' }
subject { links.for(submodule_item, ref) }
context 'when there is no .gitmodules file' do
before do
stub_urls(nil)
end
it 'returns no links' do
expect(subject).to eq([nil, nil])
end
end
context 'when the submodule is unknown' do
before do
stub_urls({ 'path' => 'url' })
end
it 'returns no links' do
expect(subject).to eq([nil, nil])
end
end
context 'when the submodule is known' do
before do
stub_urls({ 'gitlab-foss' => 'git@gitlab.com:gitlab-org/gitlab-foss.git' })
end
it 'returns links and caches the by ref' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash'])
cache_store = links.instance_variable_get("@cache_store")
expect(cache_store[ref]).to eq({ "gitlab-foss" => "git@gitlab.com:gitlab-org/gitlab-foss.git" })
end
context 'when ref name contains a dash' do
let(:ref) { 'signed-commits' }
it 'returns links' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash'])
end
end
end
end
def stub_urls(urls)
allow(repo).to receive(:submodule_urls_for).and_return(urls)
end
end
|