2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::SubmoduleLinks do
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:submodule_item) { double(id: 'hash', path: 'gitlab-foss') }
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:repo) { double }
|
|
|
|
let(:links) { described_class.new(repo) }
|
|
|
|
|
|
|
|
describe '#for' do
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:ref) { 'ref' }
|
|
|
|
|
|
|
|
subject { links.for(submodule_item, ref) }
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
context 'when there is no .gitmodules file' do
|
|
|
|
before do
|
|
|
|
stub_urls(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no links' do
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(subject).to be_nil
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the submodule is unknown' do
|
|
|
|
before do
|
|
|
|
stub_urls({ 'path' => 'url' })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no links' do
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(subject).to be_nil
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the submodule is known' do
|
|
|
|
before do
|
2020-11-24 15:15:51 +05:30
|
|
|
gitlab_foss = 'git@gitlab.com:gitlab-org/gitlab-foss.git'
|
|
|
|
|
|
|
|
stub_urls({
|
|
|
|
'ref' => { 'gitlab-foss' => gitlab_foss },
|
|
|
|
'other_ref' => { 'gitlab-foss' => gitlab_foss },
|
|
|
|
'signed-commits' => { 'gitlab-foss' => gitlab_foss },
|
|
|
|
'special_ref' => { 'gitlab-foss' => 'git@OTHER.com:gitlab-org/gitlab-foss.git' }
|
|
|
|
})
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns links and caches the by ref' do
|
2020-11-24 15:15:51 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(subject.web).to eq('https://gitlab.com/gitlab-org/gitlab-foss')
|
|
|
|
expect(subject.tree).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash')
|
|
|
|
expect(subject.compare).to be_nil
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
cache_store = links.instance_variable_get(:@cache_store)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(subject.web).to eq('https://gitlab.com/gitlab-org/gitlab-foss')
|
|
|
|
expect(subject.tree).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash')
|
|
|
|
expect(subject.compare).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the diff information is available' do
|
|
|
|
let(:old_ref) { 'other_ref' }
|
|
|
|
let(:diff_file) { double(old_blob: double(id: 'old-hash', path: 'gitlab-foss'), old_content_sha: old_ref) }
|
|
|
|
|
|
|
|
subject { links.for(submodule_item, ref, diff_file) }
|
|
|
|
|
|
|
|
it 'the returned links include the compare link' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(subject.web).to eq('https://gitlab.com/gitlab-org/gitlab-foss')
|
|
|
|
expect(subject.tree).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash')
|
|
|
|
expect(subject.compare).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/compare/old-hash...hash')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'but the submodule url has changed' do
|
|
|
|
let(:old_ref) { 'special_ref' }
|
|
|
|
|
|
|
|
it 'the returned links do not include the compare link' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(subject.web).to eq('https://gitlab.com/gitlab-org/gitlab-foss')
|
|
|
|
expect(subject.tree).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/tree/hash')
|
|
|
|
expect(subject.compare).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def stub_urls(urls_by_ref)
|
|
|
|
allow(repo).to receive(:submodule_urls_for) do |ref|
|
|
|
|
urls_by_ref[ref] if urls_by_ref
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|