summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-11-24 09:23:56 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-12-03 12:04:49 +0100
commite35f16074d065cc60f6cd99b4b46c09e437f129c (patch)
tree0a47fb190bac3b411a3ec3ce622bcd6ebd5ac20c
parent6881d0917458f9b62542ee2908e2d258c75a8537 (diff)
downloadgitlab-ce-e35f16074d065cc60f6cd99b4b46c09e437f129c.tar.gz
Test new artifacts for pages deploy
-rw-r--r--app/services/projects/update_pages_service.rb2
-rw-r--r--spec/services/projects/update_pages_service_spec.rb108
2 files changed, 93 insertions, 17 deletions
diff --git a/app/services/projects/update_pages_service.rb b/app/services/projects/update_pages_service.rb
index d34903c9989..a773222bf17 100644
--- a/app/services/projects/update_pages_service.rb
+++ b/app/services/projects/update_pages_service.rb
@@ -18,7 +18,7 @@ module Projects
@status.enqueue!
@status.run!
- raise 'missing pages artifacts' unless build.artifacts_file?
+ raise 'missing pages artifacts' unless build.artifacts?
raise 'pages are outdated' unless latest?
# Create temporary directory in which we will extract the artifacts
diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb
index a0c83600f39..8e0965b444b 100644
--- a/spec/services/projects/update_pages_service_spec.rb
+++ b/spec/services/projects/update_pages_service_spec.rb
@@ -1,10 +1,18 @@
require "spec_helper"
describe Projects::UpdatePagesService do
- let(:project) { create(:project, :repository) }
- let(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) }
- let(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') }
+ set(:project) { create(:project, :repository) }
+ set(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) }
+ set(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') }
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) }
@@ -12,18 +20,85 @@ describe Projects::UpdatePagesService do
project.remove_pages
end
- %w(tar.gz zip).each do |format|
- context "for valid #{format}" do
- let(:file) { fixture_file_upload(Rails.root + "spec/fixtures/pages.#{format}") }
- let(:empty_file) { fixture_file_upload(Rails.root + "spec/fixtures/pages_empty.#{format}") }
- let(:metadata) do
- filename = Rails.root + "spec/fixtures/pages.#{format}.meta"
- fixture_file_upload(filename) if File.exist?(filename)
+ context 'legacy artifacts' do
+ %w(tar.gz zip).each do |format|
+ let(:extension) { format }
+
+ context "for valid #{format}" do
+ before do
+ 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
+ context 'for new artifacts' do
+ context "for a valid job" do
before do
- build.update_attributes(legacy_artifacts_file: file)
- build.update_attributes(legacy_artifacts_metadata: metadata)
+ create(:ci_job_artifact, file: file, job: build)
+ create(:ci_job_artifact, file_type: :metadata, file: metadata, job: build)
+
+ build.reload
end
describe 'pages artifacts' do
@@ -35,7 +110,7 @@ describe Projects::UpdatePagesService do
it "doesn't delete artifacts" do
expect(execute).to eq(:success)
- expect(build.reload.artifacts_file?).to eq(true)
+ expect(build.artifacts_file?).to eq(true)
end
end
@@ -74,13 +149,14 @@ describe Projects::UpdatePagesService do
end
it 'fails if sha on branch is not latest' do
- pipeline.update_attributes(sha: 'old_sha')
- build.update_attributes(legacy_artifacts_file: file)
+ 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)
+ build.job_archive.update_attributes(file: empty_file)
+
expect(execute).not_to eq(:success)
end
end