diff options
Diffstat (limited to 'spec/models/ci/build_spec.rb')
-rw-r--r-- | spec/models/ci/build_spec.rb | 145 |
1 files changed, 111 insertions, 34 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 069ac23c5a4..1e551d9ee33 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Ci::Build do it { is_expected.to have_many(:sourced_pipelines) } it { is_expected.to have_many(:job_variables) } it { is_expected.to have_many(:report_results) } + it { is_expected.to have_many(:pages_deployments) } it { is_expected.to have_one(:deployment) } it { is_expected.to have_one(:runner_session) } @@ -448,7 +449,7 @@ RSpec.describe Ci::Build do end it 'schedules BuildScheduleWorker at the right time' do - Timecop.freeze do + freeze_time do expect(Ci::BuildScheduleWorker) .to receive(:perform_at).with(be_like_time(1.minute.since), build.id) @@ -496,7 +497,7 @@ RSpec.describe Ci::Build do let(:option) { { start_in: '1 day' } } it 'returns date after 1 day' do - Timecop.freeze do + freeze_time do is_expected.to eq(1.day.since) end end @@ -506,7 +507,7 @@ RSpec.describe Ci::Build do let(:option) { { start_in: '1 week' } } it 'returns date after 1 week' do - Timecop.freeze do + freeze_time do is_expected.to eq(1.week.since) end end @@ -566,18 +567,18 @@ RSpec.describe Ci::Build do let(:runner) { create(:ci_runner, :project, projects: [build.project]) } before do - runner.update(contacted_at: 1.second.ago) + runner.update!(contacted_at: 1.second.ago) end it { is_expected.to be_truthy } it 'that is inactive' do - runner.update(active: false) + runner.update!(active: false) is_expected.to be_falsey end it 'that is not online' do - runner.update(contacted_at: nil) + runner.update!(contacted_at: nil) is_expected.to be_falsey end @@ -612,6 +613,46 @@ RSpec.describe Ci::Build do end end + describe '#locked_artifacts?' do + subject(:locked_artifacts) { build.locked_artifacts? } + + context 'when pipeline is artifacts_locked' do + before do + build.pipeline.artifacts_locked! + end + + context 'artifacts archive does not exist' do + let(:build) { create(:ci_build) } + + it { is_expected.to be_falsy } + end + + context 'artifacts archive exists' do + let(:build) { create(:ci_build, :artifacts) } + + it { is_expected.to be_truthy } + end + end + + context 'when pipeline is unlocked' do + before do + build.pipeline.unlocked! + end + + context 'artifacts archive does not exist' do + let(:build) { create(:ci_build) } + + it { is_expected.to be_falsy } + end + + context 'artifacts archive exists' do + let(:build) { create(:ci_build, :artifacts) } + + it { is_expected.to be_falsy } + end + end + end + describe '#available_artifacts?' do let(:build) { create(:ci_build) } @@ -683,7 +724,7 @@ RSpec.describe Ci::Build do context 'is expired' do before do - build.update(artifacts_expire_at: Time.current - 7.days) + build.update!(artifacts_expire_at: Time.current - 7.days) end it { is_expected.to be_truthy } @@ -691,7 +732,7 @@ RSpec.describe Ci::Build do context 'is not expired' do before do - build.update(artifacts_expire_at: Time.current + 7.days) + build.update!(artifacts_expire_at: Time.current + 7.days) end it { is_expected.to be_falsey } @@ -1012,18 +1053,53 @@ RSpec.describe Ci::Build do end describe '#hide_secrets' do + let(:metrics) { spy('metrics') } let(:subject) { build.hide_secrets(data) } context 'hide runners token' do let(:data) { "new #{project.runners_token} data"} it { is_expected.to match(/^new x+ data$/) } + + it 'increments trace mutation metric' do + build.hide_secrets(data, metrics) + + expect(metrics) + .to have_received(:increment_trace_operation) + .with(operation: :mutated) + end end context 'hide build token' do let(:data) { "new #{build.token} data"} it { is_expected.to match(/^new x+ data$/) } + + it 'increments trace mutation metric' do + build.hide_secrets(data, metrics) + + expect(metrics) + .to have_received(:increment_trace_operation) + .with(operation: :mutated) + end + end + + context 'when build does not include secrets' do + let(:data) { 'my build log' } + + it 'does not mutate trace' do + trace = build.hide_secrets(data) + + expect(trace).to eq data + end + + it 'does not increment trace mutation metric' do + build.hide_secrets(data, metrics) + + expect(metrics) + .not_to have_received(:increment_trace_operation) + .with(operation: :mutated) + end end end @@ -1200,7 +1276,7 @@ RSpec.describe Ci::Build do context 'when environment is defined' do before do - build.update(environment: 'review') + build.update!(environment: 'review') end it { is_expected.to be_truthy } @@ -1208,7 +1284,7 @@ RSpec.describe Ci::Build do context 'when environment is not defined' do before do - build.update(environment: nil) + build.update!(environment: nil) end it { is_expected.to be_falsey } @@ -1316,7 +1392,7 @@ RSpec.describe Ci::Build do context 'when environment is defined' do before do - build.update(environment: 'review') + build.update!(environment: 'review') end context 'no action is defined' do @@ -1325,7 +1401,7 @@ RSpec.describe Ci::Build do context 'and start action is defined' do before do - build.update(options: { environment: { action: 'start' } } ) + build.update!(options: { environment: { action: 'start' } } ) end it { is_expected.to be_truthy } @@ -1334,7 +1410,7 @@ RSpec.describe Ci::Build do context 'when environment is not defined' do before do - build.update(environment: nil) + build.update!(environment: nil) end it { is_expected.to be_falsey } @@ -1346,7 +1422,7 @@ RSpec.describe Ci::Build do context 'when environment is defined' do before do - build.update(environment: 'review') + build.update!(environment: 'review') end context 'no action is defined' do @@ -1355,7 +1431,7 @@ RSpec.describe Ci::Build do context 'and stop action is defined' do before do - build.update(options: { environment: { action: 'stop' } } ) + build.update!(options: { environment: { action: 'stop' } } ) end it { is_expected.to be_truthy } @@ -1364,7 +1440,7 @@ RSpec.describe Ci::Build do context 'when environment is not defined' do before do - build.update(environment: nil) + build.update!(environment: nil) end it { is_expected.to be_falsey } @@ -1687,7 +1763,7 @@ RSpec.describe Ci::Build do describe '#action?' do before do - build.update(when: value) + build.update!(when: value) end subject { build.action? } @@ -2232,7 +2308,7 @@ RSpec.describe Ci::Build do describe '#has_expiring_archive_artifacts?' do context 'when artifacts have expiration date set' do before do - build.update(artifacts_expire_at: 1.day.from_now) + build.update!(artifacts_expire_at: 1.day.from_now) end context 'and job artifacts archive record exists' do @@ -2252,7 +2328,7 @@ RSpec.describe Ci::Build do context 'when artifacts do not have expiration date set' do before do - build.update(artifacts_expire_at: nil) + build.update!(artifacts_expire_at: nil) end it 'does not have expiring artifacts' do @@ -2329,6 +2405,7 @@ RSpec.describe Ci::Build do { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false }, { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }, { key: 'CI_COMMIT_REF_PROTECTED', value: (!!pipeline.protected_ref?).to_s, public: true, masked: false }, + { key: 'CI_COMMIT_TIMESTAMP', value: pipeline.git_commit_timestamp, public: true, masked: false }, { key: 'CI_BUILD_REF', value: build.sha, public: true, masked: false }, { key: 'CI_BUILD_BEFORE_SHA', value: build.before_sha, public: true, masked: false }, { key: 'CI_BUILD_REF_NAME', value: build.ref, public: true, masked: false }, @@ -2526,7 +2603,7 @@ RSpec.describe Ci::Build do end before do - build.update(user: user) + build.update!(user: user) end it { user_variables.each { |v| is_expected.to include(v) } } @@ -2562,7 +2639,7 @@ RSpec.describe Ci::Build do end before do - build.update(environment: 'production') + build.update!(environment: 'production') end shared_examples 'containing environment variables' do @@ -2589,7 +2666,7 @@ RSpec.describe Ci::Build do context 'when the URL was set from the job' do before do - build.update(options: { environment: { url: url } }) + build.update!(options: { environment: { url: url } }) end it_behaves_like 'containing environment variables' @@ -2607,7 +2684,7 @@ RSpec.describe Ci::Build do context 'when the URL was not set from the job, but environment' do before do - environment.update(external_url: url) + environment.update!(external_url: url) end it_behaves_like 'containing environment variables' @@ -2643,7 +2720,7 @@ RSpec.describe Ci::Build do context 'when build started manually' do before do - build.update(when: :manual) + build.update!(when: :manual) end let(:manual_variable) do @@ -2669,8 +2746,8 @@ RSpec.describe Ci::Build do end before do - build.update(tag: false) - pipeline.update(tag: false) + build.update!(tag: false) + pipeline.update!(tag: false) end it { is_expected.to include(branch_variable) } @@ -2682,8 +2759,8 @@ RSpec.describe Ci::Build do end before do - build.update(tag: true) - pipeline.update(tag: true) + build.update!(tag: true) + pipeline.update!(tag: true) end it { is_expected.to include(tag_variable) } @@ -2860,7 +2937,7 @@ RSpec.describe Ci::Build do context 'and is disabled for project' do before do - project.update(container_registry_enabled: false) + project.update!(container_registry_enabled: false) end it { is_expected.to include(ci_registry) } @@ -2869,7 +2946,7 @@ RSpec.describe Ci::Build do context 'and is enabled for project' do before do - project.update(container_registry_enabled: true) + project.update!(container_registry_enabled: true) end it { is_expected.to include(ci_registry) } @@ -2881,7 +2958,7 @@ RSpec.describe Ci::Build do let(:runner) { create(:ci_runner, description: 'description', tag_list: %w(docker linux)) } before do - build.update(runner: runner) + build.update!(runner: runner) end it { is_expected.to include({ key: 'CI_RUNNER_ID', value: runner.id.to_s, public: true, masked: false }) } @@ -3685,7 +3762,7 @@ RSpec.describe Ci::Build do subject { described_class.where(id: build).matches_tag_ids(tag_ids) } before do - build.update(tag_list: build_tag_list) + build.update!(tag_list: build_tag_list) end context 'when have different tags' do @@ -3731,7 +3808,7 @@ RSpec.describe Ci::Build do subject { described_class.where(id: build).with_any_tags } before do - build.update(tag_list: tag_list) + build.update!(tag_list: tag_list) end context 'when does have tags' do @@ -4087,7 +4164,7 @@ RSpec.describe Ci::Build do let(:path) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end before do |