diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config')
10 files changed, 47 insertions, 137 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb index 0505b17ea91..e83d4974bb7 100644 --- a/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/include/rules/rule_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require_dependency 'active_model' RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules::Rule do let(:factory) do diff --git a/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb index c255d6e9dd6..d5988dbbb58 100644 --- a/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require_dependency 'active_model' RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules do let(:factory) do diff --git a/spec/lib/gitlab/ci/config/entry/include_spec.rb b/spec/lib/gitlab/ci/config/entry/include_spec.rb index 275cdcddeb0..fd7f85c9298 100644 --- a/spec/lib/gitlab/ci/config/entry/include_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/include_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require_dependency 'active_model' RSpec.describe ::Gitlab::Ci::Config::Entry::Include do subject(:include_entry) { described_class.new(config) } diff --git a/spec/lib/gitlab/ci/config/entry/jobs_spec.rb b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb index 9a2a67389fc..b03175cd80f 100644 --- a/spec/lib/gitlab/ci/config/entry/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb @@ -70,6 +70,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Jobs do it 'reports error' do expect(entry.errors).to include 'jobs rspec config should implement a script: or a trigger: keyword' end + + context 'when the job name cannot be cast directly to a symbol' do + let(:config) { { true => nil } } + + it 'properly parses the job name without raising a NoMethodError' do + expect(entry.errors).to include 'jobs true config should implement a script: or a trigger: keyword' + end + end end context 'when no visible jobs present' do diff --git a/spec/lib/gitlab/ci/config/entry/policy_spec.rb b/spec/lib/gitlab/ci/config/entry/policy_spec.rb index 46800055dd9..e5de0fb38e3 100644 --- a/spec/lib/gitlab/ci/config/entry/policy_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/policy_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require 'fast_spec_helper' -require 'support/helpers/stub_feature_flags' -require_dependency 'active_model' +require 'spec_helper' RSpec.describe Gitlab::Ci::Config::Entry::Policy do let(:entry) { described_class.new(config) } @@ -47,6 +45,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Policy do end context 'when using unsafe regexp' do + # When removed we could use `require 'fast_spec_helper'` again. include StubFeatureFlags let(:config) { ['/^(?!master).+/'] } @@ -89,7 +88,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Policy do describe '#errors' do it 'saves errors' do expect(entry.errors) - .to include /policy config should be an array of strings or regexps/ + .to include /policy config should be an array of strings or regular expressions/ end end end @@ -107,6 +106,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Policy do end context 'when using unsafe regexp' do + # When removed we could use `require 'fast_spec_helper'` again. include StubFeatureFlags let(:config) { { refs: ['/^(?!master).+/'] } } diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb index 749d1386ed9..daf58aff116 100644 --- a/spec/lib/gitlab/ci/config/entry/root_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb @@ -55,13 +55,13 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do } end - context 'when deprecated types keyword is defined' do + context 'when deprecated types/type keywords are defined' do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:hash) do { types: %w(test deploy), - rspec: { script: 'rspec' } } + rspec: { script: 'rspec', type: 'test' } } end before do @@ -69,11 +69,15 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do end it 'returns array of types as stages with a warning' do + expect(root.jobs_value[:rspec][:stage]).to eq 'test' expect(root.stages_value).to eq %w[test deploy] - expect(root.warnings).to match_array(["root `types` is deprecated in 9.0 and will be removed in 15.0."]) + expect(root.warnings).to match_array([ + "root `types` is deprecated in 9.0 and will be removed in 15.0.", + "jobs:rspec `type` is deprecated in 9.0 and will be removed in 15.0." + ]) end - it 'logs usage of types keyword' do + it 'logs usage of keywords' do expect(Gitlab::AppJsonLogger).to( receive(:info) .with(event: 'ci_used_deprecated_keyword', @@ -350,9 +354,9 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do root.compose! end - context 'when before script is not an array' do + context 'when before script is a number' do let(:hash) do - { before_script: 'ls' } + { before_script: 123 } end describe '#valid?' do @@ -364,7 +368,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do describe '#errors' do it 'reports errors from child nodes' do expect(root.errors) - .to include 'before_script config should be an array containing strings and arrays of strings' + .to include 'before_script config should be a string or a nested array of strings up to 10 levels deep' end end end diff --git a/spec/lib/gitlab/ci/config/entry/script_spec.rb b/spec/lib/gitlab/ci/config/entry/script_spec.rb deleted file mode 100644 index 1ddf7881e81..00000000000 --- a/spec/lib/gitlab/ci/config/entry/script_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Ci::Config::Entry::Script do - let(:entry) { described_class.new(config) } - - describe 'validations' do - context 'when entry config value is array of strings' do - let(:config) { %w(ls pwd) } - - describe '#value' do - it 'returns array of strings' do - expect(entry.value).to eq config - end - end - - describe '#errors' do - it 'does not append errors' do - expect(entry.errors).to be_empty - end - end - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when entry config value is array of arrays of strings' do - let(:config) { [['ls'], ['pwd', 'echo 1']] } - - describe '#value' do - it 'returns array of strings' do - expect(entry.value).to eq ['ls', 'pwd', 'echo 1'] - end - end - - describe '#errors' do - it 'does not append errors' do - expect(entry.errors).to be_empty - end - end - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when entry config value is array containing strings and arrays of strings' do - let(:config) { ['ls', ['pwd', 'echo 1']] } - - describe '#value' do - it 'returns array of strings' do - expect(entry.value).to eq ['ls', 'pwd', 'echo 1'] - end - end - - describe '#errors' do - it 'does not append errors' do - expect(entry.errors).to be_empty - end - end - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when entry value is string' do - let(:config) { 'ls' } - - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'script config should be an array containing strings and arrays of strings' - end - end - - describe '#valid?' do - it 'is not valid' do - expect(entry).not_to be_valid - end - end - end - - context 'when entry value is multi-level nested array' do - let(:config) { [['ls', ['echo 1']], 'pwd'] } - - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'script config should be an array containing strings and arrays of strings' - end - end - - describe '#valid?' do - it 'is not valid' do - expect(entry).not_to be_valid - end - end - end - end -end diff --git a/spec/lib/gitlab/ci/config/external/mapper_spec.rb b/spec/lib/gitlab/ci/config/external/mapper_spec.rb index cebe8984741..f8754d7e124 100644 --- a/spec/lib/gitlab/ci/config/external/mapper_spec.rb +++ b/spec/lib/gitlab/ci/config/external/mapper_spec.rb @@ -175,27 +175,35 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do end end - context "when duplicate 'include' is defined" do + context "when duplicate 'include's are defined" do + let(:values) do + { include: [ + { 'local' => local_file }, + { 'local' => local_file } + ], + image: 'ruby:2.7' } + end + + it 'does not raise an exception' do + expect { subject }.not_to raise_error + end + end + + context 'when passing max number of files' do let(:values) do { include: [ { 'local' => local_file }, - { 'local' => local_file } + { 'remote' => remote_url } ], image: 'ruby:2.7' } end - it 'raises an exception' do - expect { subject }.to raise_error(described_class::DuplicateIncludesError) + before do + stub_const("#{described_class}::MAX_INCLUDES", 2) end - context 'when including multiple files from a project' do - let(:values) do - { include: { project: project.full_path, file: [local_file, local_file] } } - end - - it 'raises an exception' do - expect { subject }.to raise_error(described_class::DuplicateIncludesError) - end + it 'does not raise an exception' do + expect { subject }.not_to raise_error end end diff --git a/spec/lib/gitlab/ci/config/external/rules_spec.rb b/spec/lib/gitlab/ci/config/external/rules_spec.rb index 091bd3b07e6..e2bb55f3854 100644 --- a/spec/lib/gitlab/ci/config/external/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/external/rules_spec.rb @@ -45,7 +45,7 @@ RSpec.describe Gitlab::Ci::Config::External::Rules do let(:context) { double(project: project, sha: project.repository.tree.sha, top_level_worktree_paths: ['Dockerfile']) } before do - project.repository.create_file(project.owner, 'Dockerfile', "commit", message: 'test', branch_name: "master") + project.repository.create_file(project.first_owner, 'Dockerfile', "commit", message: 'test', branch_name: "master") end it { is_expected.to eq(true) } diff --git a/spec/lib/gitlab/ci/config/normalizer/matrix_strategy_spec.rb b/spec/lib/gitlab/ci/config/normalizer/matrix_strategy_spec.rb index a29471706cc..1cc8b462224 100644 --- a/spec/lib/gitlab/ci/config/normalizer/matrix_strategy_spec.rb +++ b/spec/lib/gitlab/ci/config/normalizer/matrix_strategy_spec.rb @@ -1,12 +1,8 @@ # frozen_string_literal: true require 'fast_spec_helper' -require 'support/helpers/stubbed_feature' -require 'support/helpers/stub_feature_flags' RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do - include StubFeatureFlags - describe '.applies_to?' do subject { described_class.applies_to?(config) } |