diff options
Diffstat (limited to 'spec/models/ci/build_spec.rb')
-rw-r--r-- | spec/models/ci/build_spec.rb | 97 |
1 files changed, 66 insertions, 31 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 6fdd8463329..857b238981b 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::Build do +RSpec.describe Ci::Build do let_it_be(:user) { create(:user) } let_it_be(:group, reload: true) { create(:group) } let_it_be(:project, reload: true) { create(:project, :repository, group: group) } @@ -1811,6 +1811,50 @@ describe Ci::Build do end end + describe '.keep_artifacts!' do + let!(:build) { create(:ci_build, artifacts_expire_at: Time.current + 7.days) } + let!(:builds_for_update) do + Ci::Build.where(id: create_list(:ci_build, 3, artifacts_expire_at: Time.current + 7.days).map(&:id)) + end + + it 'resets expire_at' do + builds_for_update.keep_artifacts! + + builds_for_update.each do |build| + expect(build.reload.artifacts_expire_at).to be_nil + end + end + + it 'does not reset expire_at for other builds' do + builds_for_update.keep_artifacts! + + expect(build.reload.artifacts_expire_at).to be_present + end + + context 'when having artifacts files' do + let!(:artifact) { create(:ci_job_artifact, job: build, expire_in: '7 days') } + let!(:artifacts_for_update) do + builds_for_update.map do |build| + create(:ci_job_artifact, job: build, expire_in: '7 days') + end + end + + it 'resets dependent objects' do + builds_for_update.keep_artifacts! + + artifacts_for_update.each do |artifact| + expect(artifact.reload.expire_at).to be_nil + end + end + + it 'does not reset dependent object for other builds' do + builds_for_update.keep_artifacts! + + expect(artifact.reload.expire_at).to be_present + end + end + end + describe '#keep_artifacts!' do let(:build) { create(:ci_build, artifacts_expire_at: Time.current + 7.days) } @@ -2336,6 +2380,7 @@ describe Ci::Build do { key: 'CI_PROJECT_PATH', value: project.full_path, public: true, masked: false }, { key: 'CI_PROJECT_PATH_SLUG', value: project.full_path_slug, public: true, masked: false }, { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true, masked: false }, + { key: 'CI_PROJECT_ROOT_NAMESPACE', value: project.namespace.root_ancestor.path, public: true, masked: false }, { key: 'CI_PROJECT_URL', value: project.web_url, public: true, masked: false }, { 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 }, @@ -2929,19 +2974,6 @@ describe Ci::Build do it { is_expected.to include(deployment_variable) } end - context 'when build has a freeze period' do - let(:freeze_variable) { { key: 'CI_DEPLOY_FREEZE', value: 'true', masked: false, public: true } } - - before do - expect_next_instance_of(Ci::FreezePeriodStatus) do |freeze_period| - expect(freeze_period).to receive(:execute) - .and_return(true) - end - end - - it { is_expected.to include(freeze_variable) } - end - context 'when project has default CI config path' do let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: '.gitlab-ci.yml', public: true, masked: false } } @@ -3269,17 +3301,6 @@ describe Ci::Build do expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1') end end - - context 'when CI instance variables are disabled' do - before do - create(:ci_instance_variable, key: 'MY_VAR', value: 'my value 1') - stub_feature_flags(ci_instance_level_variables: false) - end - - it 'does not include instance level variables' do - expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1') - end - end end describe '#any_unmet_prerequisites?' do @@ -4050,6 +4071,10 @@ describe Ci::Build do it 'parses blobs and add the results to the terraform report' do expect { build.collect_terraform_reports!(terraform_reports) }.not_to raise_error + terraform_reports.plans.each do |key, hash_value| + expect(hash_value.keys).to match_array(%w[create delete job_id job_name job_path update]) + end + expect(terraform_reports.plans).to match( a_hash_including( build.id.to_s => a_hash_including( @@ -4068,9 +4093,19 @@ describe Ci::Build do create(:ci_job_artifact, :terraform_with_corrupted_data, job: build, project: build.project) end - it 'raises an error' do - expect { build.collect_terraform_reports!(terraform_reports) }.to raise_error( - Gitlab::Ci::Parsers::Terraform::Tfplan::TfplanParserError + it 'adds invalid plan report' do + expect { build.collect_terraform_reports!(terraform_reports) }.not_to raise_error + + terraform_reports.plans.each do |key, hash_value| + expect(hash_value.keys).to match_array(%w[job_id job_name job_path tf_report_error]) + end + + expect(terraform_reports.plans).to match( + a_hash_including( + build.id.to_s => a_hash_including( + 'tf_report_error' => :invalid_json_format + ) + ) ) end end @@ -4258,15 +4293,15 @@ describe Ci::Build do end end - context 'when `release_steps` feature is required by build' do + context 'when `multi_build_steps` feature is required by build' do before do expect(build).to receive(:runner_required_feature_names) do - [:release_steps] + [:multi_build_steps] end end context 'when runner provides given feature' do - let(:runner_features) { { release_steps: true } } + let(:runner_features) { { multi_build_steps: true } } it { is_expected.to be_truthy } end |