diff options
Diffstat (limited to 'spec/models/ci/build_spec.rb')
-rw-r--r-- | spec/models/ci/build_spec.rb | 249 |
1 files changed, 213 insertions, 36 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 9f412d64d56..c2029b9240b 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -717,6 +717,22 @@ RSpec.describe Ci::Build do end end + describe '#artifacts_public?' do + subject { build.artifacts_public? } + + context 'artifacts with defaults' do + let(:build) { create(:ci_build, :artifacts) } + + it { is_expected.to be_truthy } + end + + context 'non public artifacts' do + let(:build) { create(:ci_build, :artifacts, :non_public_artifacts) } + + it { is_expected.to be_falsey } + end + end + describe '#artifacts_expired?' do subject { build.artifacts_expired? } @@ -1149,26 +1165,12 @@ RSpec.describe Ci::Build do end context 'when transits to skipped' do - context 'when cd_skipped_deployment_status is disabled' do - before do - stub_feature_flags(cd_skipped_deployment_status: false) - build.skip! - end - - it 'transits deployment status to canceled' do - expect(deployment).to be_canceled - end + before do + build.skip! end - context 'when cd_skipped_deployment_status is enabled' do - before do - stub_feature_flags(cd_skipped_deployment_status: project) - build.skip! - end - - it 'transits deployment status to skipped' do - expect(deployment).to be_skipped - end + it 'transits deployment status to skipped' do + expect(deployment).to be_skipped end end @@ -2456,6 +2458,7 @@ RSpec.describe Ci::Build do { key: 'CI_PROJECT_VISIBILITY', value: 'private', public: true, masked: false }, { key: 'CI_PROJECT_REPOSITORY_LANGUAGES', value: project.repository_languages.map(&:name).join(',').downcase, public: true, masked: false }, { key: 'CI_DEFAULT_BRANCH', value: project.default_branch, public: true, masked: false }, + { key: 'CI_PROJECT_CONFIG_PATH', value: project.ci_config_path_or_default, public: true, masked: false }, { key: 'CI_PAGES_DOMAIN', value: Gitlab.config.pages.host, public: true, masked: false }, { key: 'CI_PAGES_URL', value: project.pages_url, public: true, masked: false }, { key: 'CI_DEPENDENCY_PROXY_SERVER', value: "#{Gitlab.config.gitlab.host}:#{Gitlab.config.gitlab.port}", public: true, masked: false }, @@ -2986,7 +2989,7 @@ RSpec.describe Ci::Build do let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: 'custom', public: true, masked: false } } before do - expect_any_instance_of(Project).to receive(:ci_config_path) { 'custom' } + project.update!(ci_config_path: 'custom') end it { is_expected.to include(ci_config_path) } @@ -4343,7 +4346,7 @@ RSpec.describe Ci::Build do end describe '#supported_runner?' do - let_it_be(:build) { create(:ci_build) } + let_it_be_with_refind(:build) { create(:ci_build) } subject { build.supported_runner?(runner_features) } @@ -4408,6 +4411,41 @@ RSpec.describe Ci::Build do it { is_expected.to be_falsey } end end + + context 'when `return_exit_code` feature is required by build' do + let(:options) { { allow_failure_criteria: { exit_codes: [1] } } } + + before do + build.update!(options: options) + end + + context 'when runner provides given feature' do + let(:runner_features) { { return_exit_code: true } } + + it { is_expected.to be_truthy } + end + + context 'when runner does not provide given feature' do + let(:runner_features) { {} } + + it { is_expected.to be_falsey } + end + + context 'when the runner does not provide all of the required features' do + let(:options) do + { + allow_failure_criteria: { exit_codes: [1] }, + artifacts: { reports: { junit: "junit.xml" } } + } + end + + let(:runner_features) { { return_exit_code: true } } + + it 'requires `upload_multiple_artifacts` too' do + is_expected.to be_falsey + end + end + end end describe '#deployment_status' do @@ -4737,22 +4775,6 @@ RSpec.describe Ci::Build do describe '#debug_mode?' do subject { build.debug_mode? } - context 'when feature is disabled' do - before do - stub_feature_flags(restrict_access_to_build_debug_mode: false) - end - - it { is_expected.to eq false } - - context 'when in variables' do - before do - create(:ci_instance_variable, key: 'CI_DEBUG_TRACE', value: 'true') - end - - it { is_expected.to eq false } - end - end - context 'when CI_DEBUG_TRACE=true is in variables' do context 'when in instance variables' do before do @@ -4807,4 +4829,159 @@ RSpec.describe Ci::Build do it { is_expected.to eq false } end end + + describe '#drop_with_exit_code!' do + let(:exit_code) { 1 } + let(:options) { {} } + + before do + build.options.merge!(options) + build.save! + end + + subject(:drop_with_exit_code) do + build.drop_with_exit_code!(:unknown_failure, exit_code) + end + + shared_examples 'drops the build without changing allow_failure' do + it 'does not change allow_failure' do + expect { drop_with_exit_code } + .not_to change { build.reload.allow_failure } + end + + it 'drops the build' do + expect { drop_with_exit_code } + .to change { build.reload.failed? } + end + end + + context 'when exit_codes are not defined' do + it_behaves_like 'drops the build without changing allow_failure' + end + + context 'when allow_failure_criteria is nil' do + let(:options) { { allow_failure_criteria: nil } } + + it_behaves_like 'drops the build without changing allow_failure' + end + + context 'when exit_codes is nil' do + let(:options) do + { + allow_failure_criteria: { + exit_codes: nil + } + } + end + + it_behaves_like 'drops the build without changing allow_failure' + end + + context 'when exit_codes do not match' do + let(:options) do + { + allow_failure_criteria: { + exit_codes: [2, 3, 4] + } + } + end + + it_behaves_like 'drops the build without changing allow_failure' + end + + context 'with matching exit codes' do + let(:options) do + { allow_failure_criteria: { exit_codes: [1, 2, 3] } } + end + + it 'changes allow_failure' do + expect { drop_with_exit_code } + .to change { build.reload.allow_failure } + end + + it 'drops the build' do + expect { drop_with_exit_code } + .to change { build.reload.failed? } + end + + it 'is executed inside a transaction' do + expect(build).to receive(:drop!) + .with(:unknown_failure) + .and_raise(ActiveRecord::Rollback) + + expect(build).to receive(:conditionally_allow_failure!) + .with(1) + .and_call_original + + expect { drop_with_exit_code } + .not_to change { build.reload.allow_failure } + end + + context 'when exit_code is nil' do + let(:exit_code) {} + + it_behaves_like 'drops the build without changing allow_failure' + end + + context 'when ci_allow_failure_with_exit_codes is disabled' do + before do + stub_feature_flags(ci_allow_failure_with_exit_codes: false) + end + + it_behaves_like 'drops the build without changing allow_failure' + end + end + end + + describe '#exit_codes_defined?' do + let(:options) { {} } + + before do + build.options.merge!(options) + end + + subject(:exit_codes_defined) do + build.exit_codes_defined? + end + + context 'without allow_failure_criteria' do + it { is_expected.to be_falsey } + end + + context 'when exit_codes is nil' do + let(:options) do + { + allow_failure_criteria: { + exit_codes: nil + } + } + end + + it { is_expected.to be_falsey } + end + + context 'when exit_codes is an empty array' do + let(:options) do + { + allow_failure_criteria: { + exit_codes: [] + } + } + end + + it { is_expected.to be_falsey } + end + + context 'when exit_codes are defined' do + let(:options) do + { + allow_failure_criteria: { + exit_codes: [5, 6] + } + } + end + + it { is_expected.to be_truthy } + end + end end |