diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/pages.tar.gz | bin | 0 -> 1795 bytes | |||
-rw-r--r-- | spec/fixtures/pages_empty.tar.gz | bin | 0 -> 128 bytes | |||
-rw-r--r-- | spec/services/update_pages_service_spec.rb | 43 | ||||
-rw-r--r-- | spec/tasks/gitlab/backup_rake_spec.rb | 14 | ||||
-rw-r--r-- | spec/workers/pages_worker_spec.rb | 58 |
5 files changed, 110 insertions, 5 deletions
diff --git a/spec/fixtures/pages.tar.gz b/spec/fixtures/pages.tar.gz Binary files differnew file mode 100644 index 00000000000..d0e89378b3e --- /dev/null +++ b/spec/fixtures/pages.tar.gz diff --git a/spec/fixtures/pages_empty.tar.gz b/spec/fixtures/pages_empty.tar.gz Binary files differnew file mode 100644 index 00000000000..5c2afa1a8f6 --- /dev/null +++ b/spec/fixtures/pages_empty.tar.gz diff --git a/spec/services/update_pages_service_spec.rb b/spec/services/update_pages_service_spec.rb new file mode 100644 index 00000000000..ed392cd94ee --- /dev/null +++ b/spec/services/update_pages_service_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe UpdatePagesService, services: true do + let(:build) { create(:ci_build) } + let(:data) { Gitlab::BuildDataBuilder.build(build) } + let(:service) { UpdatePagesService.new(data) } + + context 'execute asynchronously for pages job' do + before { build.name = 'pages' } + + context 'on success' do + before { build.success } + + it 'should execute worker' do + expect(PagesWorker).to receive(:perform_async) + service.execute + end + end + + %w(pending running failed canceled).each do |status| + context "on #{status}" do + before { build.status = status } + + it 'should not execute worker' do + expect(PagesWorker).to_not receive(:perform_async) + service.execute + end + end + end + end + + context 'for other jobs' do + before do + build.name = 'other job' + build.success + end + + it 'should not execute worker' do + expect(PagesWorker).to_not receive(:perform_async) + service.execute + end + end +end diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb index bc751d20ce1..df8a47893f9 100644 --- a/spec/tasks/gitlab/backup_rake_spec.rb +++ b/spec/tasks/gitlab/backup_rake_spec.rb @@ -28,7 +28,7 @@ describe 'gitlab:app namespace rake task' do end def reenable_backup_sub_tasks - %w{db repo uploads builds artifacts lfs registry}.each do |subtask| + %w{db repo uploads builds artifacts pages lfs registry}.each do |subtask| Rake::Task["gitlab:backup:#{subtask}:create"].reenable end end @@ -71,6 +71,7 @@ describe 'gitlab:app namespace rake task' do expect(Rake::Task['gitlab:backup:builds:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:uploads:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:artifacts:restore']).to receive(:invoke) + expect(Rake::Task['gitlab:backup:pages:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:lfs:restore']).to receive(:invoke) expect(Rake::Task['gitlab:backup:registry:restore']).to receive(:invoke) expect(Rake::Task['gitlab:shell:setup']).to receive(:invoke) @@ -202,7 +203,7 @@ describe 'gitlab:app namespace rake task' do it 'sets correct permissions on the tar contents' do tar_contents, exit_status = Gitlab::Popen.popen( - %W{tar -tvf #{@backup_tar} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz registry.tar.gz} + %W{tar -tvf #{@backup_tar} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz registry.tar.gz} ) expect(exit_status).to eq(0) expect(tar_contents).to match('db/') @@ -210,14 +211,15 @@ describe 'gitlab:app namespace rake task' do expect(tar_contents).to match('repositories/') expect(tar_contents).to match('builds.tar.gz') expect(tar_contents).to match('artifacts.tar.gz') + expect(tar_contents).to match('pages.tar.gz') expect(tar_contents).to match('lfs.tar.gz') expect(tar_contents).to match('registry.tar.gz') - expect(tar_contents).not_to match(/^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|artifacts.tar.gz|registry.tar.gz)\/$/) + expect(tar_contents).not_to match(/^.{4,9}[rwx].* (database.sql.gz|uploads.tar.gz|repositories|builds.tar.gz|pages.tar.gz|artifacts.tar.gz|registry.tar.gz)\/$/) end it 'deletes temp directories' do temp_dirs = Dir.glob( - File.join(Gitlab.config.backup.path, '{db,repositories,uploads,builds,artifacts,lfs,registry}') + File.join(Gitlab.config.backup.path, '{db,repositories,uploads,builds,artifacts,pages,lfs,registry}') ) expect(temp_dirs).to be_empty @@ -304,7 +306,7 @@ describe 'gitlab:app namespace rake task' do it "does not contain skipped item" do tar_contents, _exit_status = Gitlab::Popen.popen( - %W{tar -tvf #{@backup_tar} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz lfs.tar.gz registry.tar.gz} + %W{tar -tvf #{@backup_tar} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz registry.tar.gz} ) expect(tar_contents).to match('db/') @@ -312,6 +314,7 @@ describe 'gitlab:app namespace rake task' do expect(tar_contents).to match('builds.tar.gz') expect(tar_contents).to match('artifacts.tar.gz') expect(tar_contents).to match('lfs.tar.gz') + expect(tar_contents).to match('pages.tar.gz') expect(tar_contents).to match('registry.tar.gz') expect(tar_contents).not_to match('repositories/') end @@ -327,6 +330,7 @@ describe 'gitlab:app namespace rake task' do expect(Rake::Task['gitlab:backup:uploads:restore']).not_to receive :invoke expect(Rake::Task['gitlab:backup:builds:restore']).to receive :invoke expect(Rake::Task['gitlab:backup:artifacts:restore']).to receive :invoke + expect(Rake::Task['gitlab:backup:pages:restore']).to receive :invoke expect(Rake::Task['gitlab:backup:lfs:restore']).to receive :invoke expect(Rake::Task['gitlab:backup:registry:restore']).to receive :invoke expect(Rake::Task['gitlab:shell:setup']).to receive :invoke diff --git a/spec/workers/pages_worker_spec.rb b/spec/workers/pages_worker_spec.rb new file mode 100644 index 00000000000..158a4b3ba8d --- /dev/null +++ b/spec/workers/pages_worker_spec.rb @@ -0,0 +1,58 @@ +require "spec_helper" + +describe PagesWorker do + let(:project) { create :project } + let(:commit) { create :ci_commit, project: project, sha: project.commit('HEAD').sha } + let(:build) { create :ci_build, commit: commit, ref: 'HEAD' } + let(:worker) { PagesWorker.new } + let(:file) { fixture_file_upload(Rails.root + 'spec/fixtures/pages.tar.gz', 'application/octet-stream') } + let(:empty_file) { fixture_file_upload(Rails.root + 'spec/fixtures/pages_empty.tar.gz', 'application/octet-stream') } + let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'application/octet-stream') } + + before do + project.remove_pages + end + + context 'for valid file' do + before { build.update_attributes(artifacts_file: file) } + + it 'succeeds' do + expect(project.pages_url).to be_nil + expect(worker.perform(build.id)).to be_truthy + expect(project.pages_url).to_not be_nil + end + + it 'limits pages size' do + stub_application_setting(max_pages_size: 1) + expect(worker.perform(build.id)).to_not be_truthy + end + + it 'removes pages after destroy' do + expect(project.pages_url).to be_nil + expect(worker.perform(build.id)).to be_truthy + expect(project.pages_url).to_not be_nil + project.destroy + expect(Dir.exist?(project.public_pages_path)).to be_falsey + end + end + + it 'fails if no artifacts' do + expect(worker.perform(build.id)).to_not be_truthy + end + + it 'fails for empty file fails' do + build.update_attributes(artifacts_file: empty_file) + expect(worker.perform(build.id)).to_not be_truthy + end + + it 'fails for invalid archive' do + build.update_attributes(artifacts_file: invalid_file) + expect(worker.perform(build.id)).to_not be_truthy + end + + it 'fails if sha on branch is not latest' do + commit.update_attributes(sha: 'old_sha') + build.update_attributes(artifacts_file: file) + expect(worker.perform(build.id)).to_not be_truthy + end +end |