1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectCiCdSetting, feature_category: :continuous_integration do
using RSpec::Parameterized::TableSyntax
describe 'validations' do
it 'validates default_git_depth is between 0 and 1000 or nil' do
expect(subject).to validate_numericality_of(:default_git_depth)
.only_integer
.is_greater_than_or_equal_to(0)
.is_less_than_or_equal_to(1000)
.allow_nil
end
it 'validates id_token_sub_claim_components with minimum length 1' do
subject.id_token_sub_claim_components = []
expect(subject).not_to be_valid
expect(subject.errors[:id_token_sub_claim_components]).to include("is too short (minimum is 1 character)")
end
it 'validates id_token_sub_claim_components with project_path in the beginning' do
subject.id_token_sub_claim_components = ['ref']
expect(subject).not_to be_valid
expect(subject.errors[:id_token_sub_claim_components])
.to include("project_path must be the first element of the sub claim")
end
it 'validates invalid claim name' do
subject.id_token_sub_claim_components = %w[project_path not_existing_claim]
expect(subject).not_to be_valid
expect(subject.errors[:id_token_sub_claim_components])
.to include("not_existing_claim is not an allowed sub claim component")
end
end
describe '#pipeline_variables_minimum_override_role' do
it 'is maintainer by default' do
expect(described_class.new.pipeline_variables_minimum_override_role).to eq('maintainer')
end
end
describe '#id_token_sub_claim_components' do
it 'is project_path, ref_type, ref by default' do
expect(described_class.new.id_token_sub_claim_components).to eq(%w[project_path ref_type ref])
end
end
describe '#forward_deployment_enabled' do
it 'is true by default' do
expect(described_class.new.forward_deployment_enabled).to be_truthy
end
end
describe '#push_repository_for_job_token_allowed' do
it 'is false by default' do
expect(described_class.new.push_repository_for_job_token_allowed).to be_falsey
end
end
describe '#separated_caches' do
it 'is true by default' do
expect(described_class.new.separated_caches).to be_truthy
end
end
describe '#default_for_inbound_job_token_scope_enabled' do
it { is_expected.to be_inbound_job_token_scope_enabled }
end
describe '#default_git_depth' do
let(:default_value) { described_class::DEFAULT_GIT_DEPTH }
it 'sets default value for new records' do
project = create(:project)
expect(project.ci_cd_settings.default_git_depth).to eq(default_value)
end
it 'does not set default value if present' do
project = build(:project)
project.build_ci_cd_settings(default_git_depth: 0)
project.save!
expect(project.reload.ci_cd_settings.default_git_depth).to eq(0)
end
end
describe '#keep_latest_artifacts_available?' do
let(:attrs) { { keep_latest_artifact: project_enabled } }
let(:project_settings) { described_class.new(attrs) }
subject { project_settings.keep_latest_artifacts_available? }
context 'without application setting record' do
where(:project_enabled, :result_keep_latest_artifact) do
false | false
true | true
end
with_them do
it { expect(subject).to eq(result_keep_latest_artifact) }
end
end
context 'with application setting record' do
where(:instance_enabled, :project_enabled, :result_keep_latest_artifact) do
false | false | false
false | true | false
true | false | false
true | true | true
end
before do
Gitlab::CurrentSettings.current_application_settings.update!(keep_latest_artifact: instance_enabled)
end
with_them do
it { expect(subject).to eq(result_keep_latest_artifact) }
end
end
end
end
|