diff options
Diffstat (limited to 'spec/models/pages/lookup_path_spec.rb')
-rw-r--r-- | spec/models/pages/lookup_path_spec.rb | 120 |
1 files changed, 102 insertions, 18 deletions
diff --git a/spec/models/pages/lookup_path_spec.rb b/spec/models/pages/lookup_path_spec.rb index cb1938a0113..f8ebc237577 100644 --- a/spec/models/pages/lookup_path_spec.rb +++ b/spec/models/pages/lookup_path_spec.rb @@ -3,15 +3,14 @@ require 'spec_helper' RSpec.describe Pages::LookupPath do - let_it_be(:project) do - create(:project, :pages_private, pages_https_only: true) - end + let(:project) { create(:project, :pages_private, pages_https_only: true) } subject(:lookup_path) { described_class.new(project) } before do stub_pages_setting(access_control: true, external_https: ["1.1.1.1:443"]) stub_artifacts_object_storage + stub_pages_object_storage(::Pages::DeploymentUploader) end describe '#project_id' do @@ -47,18 +46,78 @@ RSpec.describe Pages::LookupPath do end describe '#source' do - shared_examples 'uses disk storage' do - it 'sets the source type to "file"' do - expect(lookup_path.source[:type]).to eq('file') - end + let(:source) { lookup_path.source } - it 'sets the source path to the project full path suffixed with "public/' do - expect(lookup_path.source[:path]).to eq(project.full_path + "/public/") + shared_examples 'uses disk storage' do + it 'uses disk storage', :aggregate_failures do + expect(source[:type]).to eq('file') + expect(source[:path]).to eq(project.full_path + "/public/") end end include_examples 'uses disk storage' + context 'when there is pages deployment' do + let(:deployment) { create(:pages_deployment, project: project) } + + before do + project.mark_pages_as_deployed + project.pages_metadatum.update!(pages_deployment: deployment) + end + + it 'uses deployment from object storage' do + Timecop.freeze do + expect(source).to( + eq({ + type: 'zip', + path: deployment.file.url(expire_at: 1.day.from_now), + global_id: "gid://gitlab/PagesDeployment/#{deployment.id}", + sha256: deployment.file_sha256, + file_size: deployment.size, + file_count: deployment.file_count + }) + ) + end + end + + context 'when deployment is in the local storage' do + before do + deployment.file.migrate!(::ObjectStorage::Store::LOCAL) + end + + it 'uses file protocol' do + Timecop.freeze do + expect(source).to( + eq({ + type: 'zip', + path: 'file://' + deployment.file.path, + global_id: "gid://gitlab/PagesDeployment/#{deployment.id}", + sha256: deployment.file_sha256, + file_size: deployment.size, + file_count: deployment.file_count + }) + ) + end + end + + context 'when pages_serve_with_zip_file_protocol feature flag is disabled' do + before do + stub_feature_flags(pages_serve_with_zip_file_protocol: false) + end + + include_examples 'uses disk storage' + end + end + + context 'when pages_serve_from_deployments feature flag is disabled' do + before do + stub_feature_flags(pages_serve_from_deployments: false) + end + + include_examples 'uses disk storage' + end + end + context 'when artifact_id from build job is present in pages metadata' do let(:artifacts_archive) { create(:ci_job_artifact, :zip, :remote_store, project: project) } @@ -66,26 +125,51 @@ RSpec.describe Pages::LookupPath do project.mark_pages_as_deployed(artifacts_archive: artifacts_archive) end - it 'sets the source type to "zip"' do - expect(lookup_path.source[:type]).to eq('zip') - end - - it 'sets the source path to the artifacts archive URL' do + it 'uses artifacts object storage' do Timecop.freeze do - expect(lookup_path.source[:path]).to eq(artifacts_archive.file.url(expire_at: 1.day.from_now)) - expect(lookup_path.source[:path]).to include("Expires=86400") + expect(source).to( + eq({ + type: 'zip', + path: artifacts_archive.file.url(expire_at: 1.day.from_now), + global_id: "gid://gitlab/Ci::JobArtifact/#{artifacts_archive.id}", + sha256: artifacts_archive.file_sha256, + file_size: artifacts_archive.size, + file_count: nil + }) + ) end end context 'when artifact is not uploaded to object storage' do let(:artifacts_archive) { create(:ci_job_artifact, :zip) } - include_examples 'uses disk storage' + it 'uses file protocol', :aggregate_failures do + Timecop.freeze do + expect(source).to( + eq({ + type: 'zip', + path: 'file://' + artifacts_archive.file.path, + global_id: "gid://gitlab/Ci::JobArtifact/#{artifacts_archive.id}", + sha256: artifacts_archive.file_sha256, + file_size: artifacts_archive.size, + file_count: nil + }) + ) + end + end + + context 'when pages_serve_with_zip_file_protocol feature flag is disabled' do + before do + stub_feature_flags(pages_serve_with_zip_file_protocol: false) + end + + include_examples 'uses disk storage' + end end context 'when feature flag is disabled' do before do - stub_feature_flags(pages_artifacts_archive: false) + stub_feature_flags(pages_serve_from_artifacts_archive: false) end include_examples 'uses disk storage' |