diff options
Diffstat (limited to 'spec/models/ci/build_spec.rb')
-rw-r--r-- | spec/models/ci/build_spec.rb | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index b8c5af5a911..90298f0e973 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -3618,20 +3618,6 @@ RSpec.describe Ci::Build do build.scoped_variables end - - context 'when variables builder is used' do - it 'returns the same variables' do - build.user = create(:user) - - allow(build.pipeline).to receive(:use_variables_builder_definitions?).and_return(false) - legacy_variables = build.scoped_variables.to_hash - - allow(build.pipeline).to receive(:use_variables_builder_definitions?).and_return(true) - new_variables = build.scoped_variables.to_hash - - expect(new_variables).to eq(legacy_variables) - end - end end describe '#simple_variables_without_dependencies' do @@ -3642,160 +3628,6 @@ RSpec.describe Ci::Build do end end - shared_examples "secret CI variables" do - context 'when ref is branch' do - let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, ref: 'master', tag: false, pipeline: pipeline, project: project) } - - context 'when ref is protected' do - before do - create(:protected_branch, :developers_can_merge, name: 'master', project: project) - end - - it { is_expected.to include(variable) } - end - - context 'when ref is not protected' do - it { is_expected.not_to include(variable) } - end - end - - context 'when ref is tag' do - let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, ref: 'v1.1.0', tag: true, pipeline: pipeline, project: project) } - - context 'when ref is protected' do - before do - create(:protected_tag, project: project, name: 'v*') - end - - it { is_expected.to include(variable) } - end - - context 'when ref is not protected' do - it { is_expected.not_to include(variable) } - end - end - - context 'when ref is merge request' do - let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) } - let(:pipeline) { merge_request.pipelines_for_merge_request.first } - let(:build) { create(:ci_build, ref: merge_request.source_branch, tag: false, pipeline: pipeline, project: project) } - - context 'when ref is protected' do - before do - create(:protected_branch, :developers_can_merge, name: merge_request.source_branch, project: project) - end - - it 'does not return protected variables as it is not supported for merge request pipelines' do - is_expected.not_to include(variable) - end - end - - context 'when ref is not protected' do - it { is_expected.not_to include(variable) } - end - end - end - - describe '#secret_instance_variables' do - subject { build.secret_instance_variables } - - let_it_be(:variable) { create(:ci_instance_variable, protected: true) } - - include_examples "secret CI variables" - end - - describe '#secret_group_variables' do - subject { build.secret_group_variables } - - let_it_be(:variable) { create(:ci_group_variable, protected: true, group: group) } - - include_examples "secret CI variables" - end - - describe '#secret_project_variables' do - subject { build.secret_project_variables } - - let_it_be(:variable) { create(:ci_variable, protected: true, project: project) } - - include_examples "secret CI variables" - end - - describe '#kubernetes_variables' do - let(:build) { create(:ci_build) } - let(:service) { double(execute: template) } - let(:template) { double(to_yaml: 'example-kubeconfig', valid?: template_valid) } - let(:template_valid) { true } - - subject { build.kubernetes_variables } - - before do - allow(Ci::GenerateKubeconfigService).to receive(:new).with(build).and_return(service) - end - - it { is_expected.to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) } - - context 'generated config is invalid' do - let(:template_valid) { false } - - it { is_expected.not_to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) } - end - end - - describe '#deployment_variables' do - let(:build) { create(:ci_build, environment: environment) } - let(:environment) { 'production' } - let(:kubernetes_namespace) { 'namespace' } - let(:project_variables) { double } - - subject { build.deployment_variables(environment: environment) } - - before do - allow(build).to receive(:expanded_kubernetes_namespace) - .and_return(kubernetes_namespace) - - allow(build.project).to receive(:deployment_variables) - .with(environment: environment, kubernetes_namespace: kubernetes_namespace) - .and_return(project_variables) - end - - context 'environment is nil' do - let(:environment) { nil } - - it { is_expected.to be_empty } - end - end - - describe '#user_variables' do - subject { build.user_variables.to_hash } - - context 'with user' do - let(:expected_variables) do - { - 'GITLAB_USER_EMAIL' => user.email, - 'GITLAB_USER_ID' => user.id.to_s, - 'GITLAB_USER_LOGIN' => user.username, - 'GITLAB_USER_NAME' => user.name - } - end - - before do - build.user = user - end - - it { is_expected.to eq(expected_variables) } - end - - context 'without user' do - before do - expect(build).to receive(:user).and_return(nil) - end - - it { is_expected.to be_empty } - end - end - describe '#any_unmet_prerequisites?' do let(:build) { create(:ci_build, :created) } |