2019-09-10 19:54:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Pages::VirtualDomain do
|
2019-09-10 19:54:06 -04:00
|
|
|
describe '#certificate and #key pair' do
|
|
|
|
let(:domain) { nil }
|
|
|
|
let(:project) { instance_double(Project) }
|
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
subject(:virtual_domain) { described_class.new(projects: [project], domain: domain) }
|
2019-09-10 19:54:06 -04:00
|
|
|
|
|
|
|
it 'returns nil if there is no domain provided' do
|
|
|
|
expect(virtual_domain.certificate).to be_nil
|
|
|
|
expect(virtual_domain.key).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Pages domain is provided' do
|
|
|
|
let(:domain) { instance_double(PagesDomain, certificate: 'certificate', key: 'key') }
|
|
|
|
|
|
|
|
it 'returns certificate and key from the provided domain' do
|
|
|
|
expect(virtual_domain.certificate).to eq('certificate')
|
|
|
|
expect(virtual_domain.key).to eq('key')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#lookup_paths' do
|
|
|
|
let(:project_a) { instance_double(Project) }
|
2021-01-21 13:09:11 -05:00
|
|
|
let(:project_b) { instance_double(Project) }
|
|
|
|
let(:project_c) { instance_double(Project) }
|
|
|
|
let(:pages_lookup_path_a) { instance_double(Pages::LookupPath, prefix: 'aaa', source: { type: 'zip', path: 'https://example.com' }) }
|
|
|
|
let(:pages_lookup_path_b) { instance_double(Pages::LookupPath, prefix: 'bbb', source: { type: 'zip', path: 'https://example.com' }) }
|
|
|
|
let(:pages_lookup_path_without_source) { instance_double(Pages::LookupPath, prefix: 'ccc', source: nil) }
|
2019-09-10 19:54:06 -04:00
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
context 'when there is pages domain provided' do
|
|
|
|
let(:domain) { instance_double(PagesDomain) }
|
2019-09-10 19:54:06 -04:00
|
|
|
|
2022-07-06 11:08:08 -04:00
|
|
|
subject(:virtual_domain) { described_class.new(projects: [project_a, project_b, project_c], domain: domain) }
|
2019-09-10 19:54:06 -04:00
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do
|
|
|
|
expect(project_a).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_a)
|
2021-01-21 13:09:11 -05:00
|
|
|
expect(project_b).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_b)
|
|
|
|
expect(project_c).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_without_source)
|
2019-09-25 05:06:04 -04:00
|
|
|
|
2021-01-21 13:09:11 -05:00
|
|
|
expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_b, pages_lookup_path_a])
|
2019-09-25 05:06:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is trim_prefix provided' do
|
2022-07-06 11:08:08 -04:00
|
|
|
subject(:virtual_domain) { described_class.new(projects: [project_a, project_b], trim_prefix: 'group/') }
|
2019-09-25 05:06:04 -04:00
|
|
|
|
|
|
|
it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do
|
|
|
|
expect(project_a).to receive(:pages_lookup_path).with(trim_prefix: 'group/', domain: nil).and_return(pages_lookup_path_a)
|
2021-01-21 13:09:11 -05:00
|
|
|
expect(project_b).to receive(:pages_lookup_path).with(trim_prefix: 'group/', domain: nil).and_return(pages_lookup_path_b)
|
2019-09-25 05:06:04 -04:00
|
|
|
|
2021-01-21 13:09:11 -05:00
|
|
|
expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_b, pages_lookup_path_a])
|
2019-09-25 05:06:04 -04:00
|
|
|
end
|
2019-09-10 19:54:06 -04:00
|
|
|
end
|
|
|
|
end
|
2022-07-06 11:08:08 -04:00
|
|
|
|
|
|
|
describe '#cache_key' do
|
|
|
|
it 'returns the cache key based in the given cache_control' do
|
|
|
|
cache_control = instance_double(::Gitlab::Pages::CacheControl, cache_key: 'cache_key')
|
|
|
|
virtual_domain = described_class.new(projects: [instance_double(Project)], cache: cache_control)
|
|
|
|
|
|
|
|
expect(virtual_domain.cache_key).to eq('cache_key')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when no cache_control is given' do
|
|
|
|
virtual_domain = described_class.new(projects: [instance_double(Project)])
|
|
|
|
|
|
|
|
expect(virtual_domain.cache_key).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-09-10 19:54:06 -04:00
|
|
|
end
|