2019-07-25 18:01:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::SubmoduleLinks do
|
2019-09-18 10:02:45 -04:00
|
|
|
let(:submodule_item) { double(id: 'hash', path: 'gitlab-foss') }
|
2019-07-25 18:01:17 -04:00
|
|
|
let(:repo) { double }
|
|
|
|
let(:links) { described_class.new(repo) }
|
|
|
|
|
|
|
|
describe '#for' do
|
2019-10-16 11:06:17 -04:00
|
|
|
let(:ref) { 'ref' }
|
|
|
|
|
|
|
|
subject { links.for(submodule_item, ref) }
|
2019-07-25 18:01:17 -04:00
|
|
|
|
|
|
|
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
|
2019-09-18 10:02:45 -04:00
|
|
|
stub_urls({ 'gitlab-foss' => 'git@gitlab.com:gitlab-org/gitlab-foss.git' })
|
2019-07-25 18:01:17 -04:00
|
|
|
end
|
|
|
|
|
2019-10-16 11:06:17 -04:00
|
|
|
it 'returns links and caches the by ref' do
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash'])
|
2019-10-16 11:06:17 -04:00
|
|
|
|
|
|
|
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
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash'])
|
2019-10-16 11:06:17 -04:00
|
|
|
end
|
2019-07-25 18:01:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_urls(urls)
|
|
|
|
allow(repo).to receive(:submodule_urls_for).and_return(urls)
|
|
|
|
end
|
|
|
|
end
|