diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-08-01 13:09:06 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-08-01 13:09:06 +0000 |
commit | 71384c590cda562ed0ccf62daee66cd69ea82f4f (patch) | |
tree | b3a9b89c7e7cc40c1965ea807cdae0130b223b48 /spec | |
parent | e6b2e900383ff37c0a2ec6da68432d6c6aff9321 (diff) | |
parent | 2d0cd5262021a3af609bc5c6235d2b893c17a31a (diff) | |
download | gitlab-ce-71384c590cda562ed0ccf62daee66cd69ea82f4f.tar.gz |
Merge branch 'runner-features' into 'master'
Add `runner_unsupported` CI failure
See merge request gitlab-org/gitlab-ce!20664
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/status/build/failed_spec.rb | 27 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 91 | ||||
-rw-r--r-- | spec/presenters/commit_status_presenter_spec.rb | 26 | ||||
-rw-r--r-- | spec/services/ci/register_job_service_spec.rb | 33 |
4 files changed, 168 insertions, 9 deletions
diff --git a/spec/lib/gitlab/ci/status/build/failed_spec.rb b/spec/lib/gitlab/ci/status/build/failed_spec.rb index cadb424ea2c..b6676b40fd3 100644 --- a/spec/lib/gitlab/ci/status/build/failed_spec.rb +++ b/spec/lib/gitlab/ci/status/build/failed_spec.rb @@ -80,4 +80,31 @@ describe Gitlab::Ci::Status::Build::Failed do end end end + + describe 'covers all failure reasons' do + let(:status) { Gitlab::Ci::Status::Failed.new(build, user) } + let(:tooltip) { subject.status_tooltip } + + CommitStatus.failure_reasons.keys.each do |failure_reason| + context failure_reason do + before do + build.failure_reason = failure_reason + end + + it "is a valid status" do + expect { tooltip }.not_to raise_error + end + end + end + + context 'invalid failure message' do + before do + expect(build).to receive(:failure_reason) { 'invalid failure message' } + end + + it "is an invalid status" do + expect { tooltip }.to raise_error(/key not found:/) + end + end + end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index e4fa04baae6..6955f7f4cd8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2409,18 +2409,18 @@ describe Ci::Build do end end - describe 'state transition: any => [:running]' do + describe '#has_valid_build_dependencies?' do shared_examples 'validation is active' do context 'when depended job has not been completed yet' do let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: 'test', stage_idx: 0) } - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end context 'when artifacts of depended job has been expired' do let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) } - it { expect { job.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + it { expect(job).not_to have_valid_build_dependencies } end context 'when artifacts of depended job has been erased' do @@ -2430,7 +2430,7 @@ describe Ci::Build do pre_stage_job.erase end - it { expect { job.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + it { expect(job).not_to have_valid_build_dependencies } end end @@ -2438,12 +2438,13 @@ describe Ci::Build do context 'when depended job has not been completed yet' do let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: 'test', stage_idx: 0) } - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end + context 'when artifacts of depended job has been expired' do let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) } - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end context 'when artifacts of depended job has been erased' do @@ -2453,7 +2454,7 @@ describe Ci::Build do pre_stage_job.erase end - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end end @@ -2469,13 +2470,13 @@ describe Ci::Build do context 'when "dependencies" keyword is not defined' do let(:options) { {} } - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end context 'when "dependencies" keyword is empty' do let(:options) { { dependencies: [] } } - it { expect { job.run! }.not_to raise_error } + it { expect(job).to have_valid_build_dependencies } end context 'when "dependencies" keyword is specified' do @@ -2812,4 +2813,76 @@ describe Ci::Build do end end end + + describe '#publishes_artifacts_reports?' do + let(:build) { create(:ci_build, options: options) } + + subject { build.publishes_artifacts_reports? } + + context 'when artifacts reports are defined' do + let(:options) do + { artifacts: { reports: { junit: "junit.xml" } } } + end + + it { is_expected.to be_truthy } + end + + context 'when artifacts reports missing defined' do + let(:options) do + { artifacts: { paths: ["file.txt"] } } + end + + it { is_expected.to be_falsey } + end + + context 'when options are missing' do + let(:options) { nil } + + it { is_expected.to be_falsey } + end + end + + describe '#runner_required_feature_names' do + let(:build) { create(:ci_build, options: options) } + + subject { build.runner_required_feature_names } + + context 'when artifacts reports are defined' do + let(:options) do + { artifacts: { reports: { junit: "junit.xml" } } } + end + + it { is_expected.to include(:upload_multiple_artifacts) } + end + end + + describe '#supported_runner?' do + set(:build) { create(:ci_build) } + + subject { build.supported_runner?(runner_features) } + + context 'when feature is required by build' do + before do + expect(build).to receive(:runner_required_feature_names) do + [:upload_multiple_artifacts] + end + end + + context 'when runner provides given feature' do + let(:runner_features) do + { upload_multiple_artifacts: true } + end + + it { is_expected.to be_truthy } + end + + context 'when runner does not provide given feature' do + let(:runner_features) do + {} + end + + it { is_expected.to be_falsey } + end + end + end end diff --git a/spec/presenters/commit_status_presenter_spec.rb b/spec/presenters/commit_status_presenter_spec.rb index f81ee44e371..2b7742ddbb8 100644 --- a/spec/presenters/commit_status_presenter_spec.rb +++ b/spec/presenters/commit_status_presenter_spec.rb @@ -12,4 +12,30 @@ describe CommitStatusPresenter do it 'inherits from Gitlab::View::Presenter::Delegated' do expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated) end + + describe 'covers all failure reasons' do + let(:message) { presenter.callout_failure_message } + + CommitStatus.failure_reasons.keys.each do |failure_reason| + context failure_reason do + before do + build.failure_reason = failure_reason + end + + it "is a valid status" do + expect { message }.not_to raise_error + end + end + end + + context 'invalid failure message' do + before do + expect(build).to receive(:failure_reason) { 'invalid failure message' } + end + + it "is an invalid status" do + expect { message }.to raise_error(/key not found:/) + end + end + end end diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index dbb5e33bbdc..a6565709641 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -351,6 +351,38 @@ module Ci end end + context 'runner feature set is verified' do + let!(:pending_job) { create(:ci_build, :pending, pipeline: pipeline) } + + before do + expect_any_instance_of(Ci::Build).to receive(:runner_required_feature_names) do + [:runner_required_feature] + end + end + + subject { execute(specific_runner, params) } + + context 'when feature is missing by runner' do + let(:params) { {} } + + it 'does not pick the build and drops the build' do + expect(subject).to be_nil + expect(pending_job.reload).to be_failed + expect(pending_job).to be_runner_unsupported + end + end + + context 'when feature is supported by runner' do + let(:params) do + { info: { features: { runner_required_feature: true } } } + end + + it 'does pick job' do + expect(subject).not_to be_nil + end + end + end + context 'when "dependencies" keyword is specified' do shared_examples 'not pick' do it 'does not pick the build and drops the build' do @@ -403,6 +435,7 @@ module Ci it { expect(subject).to eq(pending_job) } end + context 'when artifacts of depended job has been expired' do let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) } |