diff options
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/expire_build_artifacts_worker_spec.rb | 57 | ||||
-rw-r--r-- | spec/workers/stuck_ci_builds_worker_spec.rb | 19 |
2 files changed, 73 insertions, 3 deletions
diff --git a/spec/workers/expire_build_artifacts_worker_spec.rb b/spec/workers/expire_build_artifacts_worker_spec.rb new file mode 100644 index 00000000000..e3827cae9a6 --- /dev/null +++ b/spec/workers/expire_build_artifacts_worker_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe ExpireBuildArtifactsWorker do + include RepoHelpers + + let(:worker) { described_class.new } + + describe '#perform' do + before { build } + + subject! { worker.perform } + + context 'with expired artifacts' do + let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) } + + it 'does expire' do + expect(build.reload.artifacts_expired?).to be_truthy + end + + it 'does remove files' do + expect(build.reload.artifacts_file.exists?).to be_falsey + end + end + + context 'with not yet expired artifacts' do + let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) } + + it 'does not expire' do + expect(build.reload.artifacts_expired?).to be_falsey + end + + it 'does not remove files' do + expect(build.reload.artifacts_file.exists?).to be_truthy + end + end + + context 'without expire date' do + let(:build) { create(:ci_build, :artifacts) } + + it 'does not expire' do + expect(build.reload.artifacts_expired?).to be_falsey + end + + it 'does not remove files' do + expect(build.reload.artifacts_file.exists?).to be_truthy + end + end + + context 'for expired artifacts' do + let(:build) { create(:ci_build, artifacts_expire_at: Time.now - 7.days) } + + it 'is still expired' do + expect(build.reload.artifacts_expired?).to be_truthy + end + end + end +end diff --git a/spec/workers/stuck_ci_builds_worker_spec.rb b/spec/workers/stuck_ci_builds_worker_spec.rb index 665ec20f224..801fa31b45d 100644 --- a/spec/workers/stuck_ci_builds_worker_spec.rb +++ b/spec/workers/stuck_ci_builds_worker_spec.rb @@ -2,6 +2,7 @@ require "spec_helper" describe StuckCiBuildsWorker do let!(:build) { create :ci_build } + let(:worker) { described_class.new } subject do build.reload @@ -16,13 +17,13 @@ describe StuckCiBuildsWorker do it 'gets dropped if it was updated over 2 days ago' do build.update!(updated_at: 2.days.ago) - StuckCiBuildsWorker.new.perform + worker.perform is_expected.to eq('failed') end it "is still #{status}" do build.update!(updated_at: 1.minute.ago) - StuckCiBuildsWorker.new.perform + worker.perform is_expected.to eq(status) end end @@ -36,9 +37,21 @@ describe StuckCiBuildsWorker do it "is still #{status}" do build.update!(updated_at: 2.days.ago) - StuckCiBuildsWorker.new.perform + worker.perform is_expected.to eq(status) end end end + + context "for deleted project" do + before do + build.update!(status: :running, updated_at: 2.days.ago) + build.project.update(pending_delete: true) + end + + it "does not drop build" do + expect_any_instance_of(Ci::Build).not_to receive(:drop) + worker.perform + end + end end |