Commit e35f1607 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Kamil Trzcinski

Test new artifacts for pages deploy

parent 6881d091
...@@ -18,7 +18,7 @@ module Projects ...@@ -18,7 +18,7 @@ module Projects
@status.enqueue! @status.enqueue!
@status.run! @status.run!
raise 'missing pages artifacts' unless build.artifacts_file? raise 'missing pages artifacts' unless build.artifacts?
raise 'pages are outdated' unless latest? raise 'pages are outdated' unless latest?
# Create temporary directory in which we will extract the artifacts # Create temporary directory in which we will extract the artifacts
......
require "spec_helper" require "spec_helper"
describe Projects::UpdatePagesService do describe Projects::UpdatePagesService do
let(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) } set(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) }
let(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') } set(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') }
let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png') } let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png') }
let(:extension) { 'zip' }
let(:file) { fixture_file_upload(Rails.root + "spec/fixtures/pages.#{extension}") }
let(:empty_file) { fixture_file_upload(Rails.root + "spec/fixtures/pages_empty.#{extension}") }
let(:metadata) do
filename = Rails.root + "spec/fixtures/pages.#{extension}.meta"
fixture_file_upload(filename) if File.exist?(filename)
end
subject { described_class.new(project, build) } subject { described_class.new(project, build) }
...@@ -12,18 +20,85 @@ describe Projects::UpdatePagesService do ...@@ -12,18 +20,85 @@ describe Projects::UpdatePagesService do
project.remove_pages project.remove_pages
end end
%w(tar.gz zip).each do |format| context 'legacy artifacts' do
context "for valid #{format}" do %w(tar.gz zip).each do |format|
let(:file) { fixture_file_upload(Rails.root + "spec/fixtures/pages.#{format}") } let(:extension) { format }
let(:empty_file) { fixture_file_upload(Rails.root + "spec/fixtures/pages_empty.#{format}") }
let(:metadata) do context "for valid #{format}" do
filename = Rails.root + "spec/fixtures/pages.#{format}.meta" before do
fixture_file_upload(filename) if File.exist?(filename) build.update_attributes(legacy_artifacts_file: file)
build.update_attributes(legacy_artifacts_metadata: metadata)
end
describe 'pages artifacts' do
context 'with expiry date' do
before do
build.artifacts_expire_in = "2 days"
end
it "doesn't delete artifacts" do
expect(execute).to eq(:success)
expect(build.reload.artifacts_file?).to eq(true)
end
end
context 'without expiry date' do
it "does delete artifacts" do
expect(execute).to eq(:success)
expect(build.reload.artifacts_file?).to eq(false)
end
end
end
it 'succeeds' do
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_deployed?).to be_truthy
# Check that all expected files are extracted
%w[index.html zero .hidden/file].each do |filename|
expect(File.exist?(File.join(project.public_pages_path, filename))).to be_truthy
end
end
it 'limits pages size' do
stub_application_setting(max_pages_size: 1)
expect(execute).not_to eq(:success)
end
it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in)
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
expect(project.pages_deployed?).to be_truthy
project.destroy
expect(project.pages_deployed?).to be_falsey
end
it 'fails if sha on branch is not latest' do
build.update_attributes(ref: 'feature')
expect(execute).not_to eq(:success)
end
it 'fails for empty file fails' do
build.update_attributes(legacy_artifacts_file: empty_file)
expect(execute).not_to eq(:success)
end
end end
end
end
context 'for new artifacts' do
context "for a valid job" do
before do before do
build.update_attributes(legacy_artifacts_file: file) create(:ci_job_artifact, file: file, job: build)
build.update_attributes(legacy_artifacts_metadata: metadata) create(:ci_job_artifact, file_type: :metadata, file: metadata, job: build)
build.reload
end end
describe 'pages artifacts' do describe 'pages artifacts' do
...@@ -35,7 +110,7 @@ describe Projects::UpdatePagesService do ...@@ -35,7 +110,7 @@ describe Projects::UpdatePagesService do
it "doesn't delete artifacts" do it "doesn't delete artifacts" do
expect(execute).to eq(:success) expect(execute).to eq(:success)
expect(build.reload.artifacts_file?).to eq(true) expect(build.artifacts_file?).to eq(true)
end end
end end
...@@ -74,13 +149,14 @@ describe Projects::UpdatePagesService do ...@@ -74,13 +149,14 @@ describe Projects::UpdatePagesService do
end end
it 'fails if sha on branch is not latest' do it 'fails if sha on branch is not latest' do
pipeline.update_attributes(sha: 'old_sha') build.update_attributes(ref: 'feature')
build.update_attributes(legacy_artifacts_file: file)
expect(execute).not_to eq(:success) expect(execute).not_to eq(:success)
end end
it 'fails for empty file fails' do it 'fails for empty file fails' do
build.update_attributes(legacy_artifacts_file: empty_file) build.job_archive.update_attributes(file: empty_file)
expect(execute).not_to eq(:success) expect(execute).not_to eq(:success)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment