Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/yaml_processor_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb330
1 files changed, 179 insertions, 151 deletions
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index cc327f5b5f1..ebf8422489e 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -15,8 +15,10 @@ module Gitlab
end
end
- describe '#build_attributes' do
- subject { described_class.new(config, user: nil).execute.build_attributes(:rspec) }
+ describe '#builds' do
+ subject(:builds) { described_class.new(config, user: nil).execute.builds }
+
+ let(:rspec_build) { builds.find { |build| build[:name] == 'rspec' } }
describe 'attributes list' do
let(:config) do
@@ -30,7 +32,7 @@ module Gitlab
end
it 'returns valid build attributes' do
- expect(subject).to eq({
+ expect(builds).to eq([{
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -45,7 +47,7 @@ module Gitlab
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
- })
+ }])
end
end
@@ -63,7 +65,7 @@ module Gitlab
end
it 'returns valid build attributes' do
- expect(subject).to eq({
+ expect(builds).to eq([{
stage: 'test',
stage_idx: 2,
name: 'rspec',
@@ -77,7 +79,7 @@ module Gitlab
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
- })
+ }])
end
end
@@ -89,21 +91,22 @@ module Gitlab
end
it 'includes coverage regexp in build attributes' do
- expect(subject)
+ expect(rspec_build)
.to include(coverage_regex: 'Code coverage: \d+\.\d+')
end
end
end
describe 'tags entry with default values' do
- it 'applies default values' do
- config = YAML.dump({ default: { tags: %w[A B] },
- rspec: { script: "rspec" } })
-
- config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ let(:config) do
+ YAML.dump(
+ default: { tags: %w[A B] },
+ rspec: { script: "rspec" }
+ )
+ end
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ it 'applies default values' do
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -125,7 +128,7 @@ module Gitlab
YAML.dump(rspec: { script: 'rspec', interruptible: true })
end
- it { expect(subject[:interruptible]).to be_truthy }
+ it { expect(rspec_build[:interruptible]).to be_truthy }
end
describe 'interruptible job with default value' do
@@ -133,7 +136,7 @@ module Gitlab
YAML.dump(rspec: { script: 'rspec' })
end
- it { expect(subject).not_to have_key(:interruptible) }
+ it { expect(rspec_build).not_to have_key(:interruptible) }
end
describe 'uninterruptible job' do
@@ -141,7 +144,7 @@ module Gitlab
YAML.dump(rspec: { script: 'rspec', interruptible: false })
end
- it { expect(subject[:interruptible]).to be_falsy }
+ it { expect(rspec_build[:interruptible]).to be_falsy }
end
it "returns interruptible when overridden for job" do
@@ -149,9 +152,10 @@ module Gitlab
rspec: { script: "rspec" } })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ builds = config_processor.builds.select { |b| b[:stage] == "test" }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(builds.size).to eq(1)
+ expect(builds.first).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -174,7 +178,7 @@ module Gitlab
end
it 'includes retry count in build options attribute' do
- expect(subject[:options]).to include(retry: { max: 1 })
+ expect(rspec_build[:options]).to include(retry: { max: 1 })
end
end
@@ -184,7 +188,7 @@ module Gitlab
end
it 'does not persist retry count in the database' do
- expect(subject[:options]).not_to have_key(:retry)
+ expect(rspec_build[:options]).not_to have_key(:retry)
end
end
@@ -195,7 +199,7 @@ module Gitlab
end
it 'does use the default value' do
- expect(subject[:options]).to include(retry: { max: 1 })
+ expect(rspec_build[:options]).to include(retry: { max: 1 })
end
end
@@ -206,7 +210,7 @@ module Gitlab
end
it 'does use the job value' do
- expect(subject[:options]).to include(retry: { max: 2 })
+ expect(rspec_build[:options]).to include(retry: { max: 2 })
end
end
end
@@ -221,7 +225,7 @@ module Gitlab
end
it 'is not allowed to fail' do
- expect(subject[:allow_failure]).to be false
+ expect(rspec_build[:allow_failure]).to be false
end
end
@@ -232,7 +236,7 @@ module Gitlab
end
it 'is allowed to fail' do
- expect(subject[:allow_failure]).to be true
+ expect(rspec_build[:allow_failure]).to be true
end
end
@@ -244,11 +248,11 @@ module Gitlab
end
it 'is not allowed to fail' do
- expect(subject[:allow_failure]).to be false
+ expect(rspec_build[:allow_failure]).to be false
end
it 'saves allow_failure_criteria into options' do
- expect(subject[:options]).to match(
+ expect(rspec_build[:options]).to match(
a_hash_including(allow_failure_criteria: { exit_codes: [1] }))
end
end
@@ -262,7 +266,7 @@ module Gitlab
end
it 'is not allowed to fail' do
- expect(subject[:allow_failure]).to be false
+ expect(rspec_build[:allow_failure]).to be false
end
end
@@ -272,7 +276,7 @@ module Gitlab
end
it 'is not allowed to fail' do
- expect(subject[:allow_failure]).to be false
+ expect(rspec_build[:allow_failure]).to be false
end
end
@@ -283,11 +287,11 @@ module Gitlab
end
it 'is not allowed to fail' do
- expect(subject[:allow_failure]).to be false
+ expect(rspec_build[:allow_failure]).to be false
end
it 'saves allow_failure_criteria into options' do
- expect(subject[:options]).to match(
+ expect(rspec_build[:options]).to match(
a_hash_including(allow_failure_criteria: { exit_codes: [1] }))
end
end
@@ -305,8 +309,8 @@ module Gitlab
end
it 'has the attributes' do
- expect(subject[:when]).to eq 'delayed'
- expect(subject[:options][:start_in]).to eq '1 day'
+ expect(rspec_build[:when]).to eq 'delayed'
+ expect(rspec_build[:options][:start_in]).to eq '1 day'
end
end
end
@@ -321,7 +325,7 @@ module Gitlab
end
it 'has the attributes' do
- expect(subject[:resource_group_key]).to eq 'iOS'
+ expect(rspec_build[:resource_group_key]).to eq 'iOS'
end
end
end
@@ -337,7 +341,7 @@ module Gitlab
end
it 'has the attributes' do
- expect(subject[:options]).to eq(
+ expect(rspec_build[:options]).to eq(
trigger: { project: 'namespace/project', branch: 'main' }
)
end
@@ -353,7 +357,7 @@ module Gitlab
end
it 'has the attributes' do
- expect(subject[:options]).to eq(
+ expect(rspec_build[:options]).to eq(
trigger: { project: 'namespace/project', forward: { pipeline_variables: true } }
)
end
@@ -510,6 +514,35 @@ module Gitlab
expect(subject.root_variables).to eq([])
end
end
+
+ context 'with name' do
+ let(:config) do
+ <<-EOYML
+ workflow:
+ name: 'Pipeline name'
+
+ hello:
+ script: echo world
+ EOYML
+ end
+
+ it 'parses the workflow:name as workflow_name' do
+ expect(subject.workflow_name).to eq('Pipeline name')
+ end
+ end
+
+ context 'with no name' do
+ let(:config) do
+ <<-EOYML
+ hello:
+ script: echo world
+ EOYML
+ end
+
+ it 'parses the workflow:name' do
+ expect(subject.workflow_name).to be_nil
+ end
+ end
end
describe '#warnings' do
@@ -682,7 +715,7 @@ module Gitlab
let(:config_data) { YAML.dump(config) }
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config_data).execute }
- subject { config_processor.stage_builds_attributes('test').first }
+ subject(:test_build) { config_processor.builds.find { |build| build[:name] == 'test' } }
describe "before_script" do
context "in global context" do
@@ -850,9 +883,9 @@ module Gitlab
rspec: { script: "rspec" } })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -884,9 +917,9 @@ module Gitlab
script: "rspec" } })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -916,9 +949,9 @@ module Gitlab
rspec: { script: "rspec" } })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -944,9 +977,9 @@ module Gitlab
rspec: { image: "image:1.0", services: ["postgresql", "docker:dind"], script: "rspec" } })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -981,7 +1014,7 @@ module Gitlab
it { is_expected.to be_valid }
it "returns with image" do
- expect(processor.stage_builds_attributes("test")).to contain_exactly({
+ expect(processor.builds).to contain_exactly({
stage: "test",
stage_idx: 2,
name: "test",
@@ -1014,7 +1047,7 @@ module Gitlab
it { is_expected.to be_valid }
it "returns with service" do
- expect(processor.stage_builds_attributes("test")).to contain_exactly({
+ expect(processor.builds).to contain_exactly({
stage: "test",
stage_idx: 2,
name: "test",
@@ -1033,8 +1066,7 @@ module Gitlab
end
end
- # Change this to a `describe` block when removing the FF ci_variables_refactoring_to_variable
- shared_examples 'Variables' do
+ describe 'Variables' do
subject(:execute) { described_class.new(config).execute }
let(:build) { execute.builds.first }
@@ -1163,18 +1195,6 @@ module Gitlab
end
end
- context 'when ci_variables_refactoring_to_variable is enabled' do
- it_behaves_like 'Variables'
- end
-
- context 'when ci_variables_refactoring_to_variable is disabled' do
- before do
- stub_feature_flags(ci_variables_refactoring_to_variable: false)
- end
-
- it_behaves_like 'Variables'
- end
-
context 'when using `extends`' do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config).execute }
@@ -1375,7 +1395,7 @@ module Gitlab
})
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
- builds = config_processor.stage_builds_attributes("test")
+ builds = config_processor.builds
expect(builds.size).to eq(1)
expect(builds.first[:when]).to eq(when_state)
@@ -1391,7 +1411,7 @@ module Gitlab
end
it 'creates one build and sets when:' do
- builds = subject.stage_builds_attributes("test")
+ builds = processor.builds
expect(builds.size).to eq(1)
expect(builds.first[:when]).to eq('delayed')
@@ -1419,7 +1439,7 @@ module Gitlab
end
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config).execute }
- let(:builds) { config_processor.stage_builds_attributes('test') }
+ let(:builds) { config_processor.builds }
context 'when job is parallelized' do
let(:parallel) { 5 }
@@ -1535,15 +1555,16 @@ module Gitlab
})
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq([
- paths: ["logs/", "binaries/"],
- untracked: true,
- key: 'key',
- policy: 'pull-push',
- when: 'on_success'
- ])
+ expect(rspec_build[:cache]).to eq(
+ [
+ paths: ["logs/", "binaries/"],
+ untracked: true,
+ key: 'key',
+ policy: 'pull-push',
+ when: 'on_success'
+ ])
end
it "returns cache when defined in default context" do
@@ -1558,32 +1579,34 @@ module Gitlab
})
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq([
- paths: ["logs/", "binaries/"],
- untracked: true,
- key: { files: ['file'] },
- policy: 'pull-push',
- when: 'on_success'
- ])
+ expect(rspec_build[:cache]).to eq(
+ [
+ paths: ["logs/", "binaries/"],
+ untracked: true,
+ key: { files: ['file'] },
+ policy: 'pull-push',
+ when: 'on_success'
+ ])
end
it 'returns cache key/s when defined in a job' do
- config = YAML.dump({
- rspec: {
- cache: [
- { paths: ['binaries/'], untracked: true, key: 'keya' },
- { paths: ['logs/', 'binaries/'], untracked: true, key: 'key' }
- ],
- script: 'rspec'
- }
- })
+ config = YAML.dump(
+ {
+ rspec: {
+ cache: [
+ { paths: ['binaries/'], untracked: true, key: 'keya' },
+ { paths: ['logs/', 'binaries/'], untracked: true, key: 'key' }
+ ],
+ script: 'rspec'
+ }
+ })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq(
+ expect(rspec_build[:cache]).to eq(
[
{
paths: ['binaries/'],
@@ -1616,15 +1639,16 @@ module Gitlab
)
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq([
- paths: ['binaries/'],
- untracked: true,
- key: { files: ['file'] },
- policy: 'pull-push',
- when: 'on_success'
- ])
+ expect(rspec_build[:cache]).to eq(
+ [
+ paths: ['binaries/'],
+ untracked: true,
+ key: { files: ['file'] },
+ policy: 'pull-push',
+ when: 'on_success'
+ ])
end
it 'returns cache files with prefix' do
@@ -1640,61 +1664,65 @@ module Gitlab
)
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes('test').size).to eq(1)
- expect(config_processor.stage_builds_attributes('test').first[:cache]).to eq([
- paths: ['logs/', 'binaries/'],
- untracked: true,
- key: { files: ['file'], prefix: 'prefix' },
- policy: 'pull-push',
- when: 'on_success'
- ])
+ expect(rspec_build[:cache]).to eq(
+ [
+ paths: ['logs/', 'binaries/'],
+ untracked: true,
+ key: { files: ['file'], prefix: 'prefix' },
+ policy: 'pull-push',
+ when: 'on_success'
+ ])
end
it "overwrite cache when defined for a job and globally" do
- config = YAML.dump({
- cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'global' },
- rspec: {
- script: "rspec",
- cache: { paths: ["test/"], untracked: false, key: 'local' }
- }
- })
+ config = YAML.dump(
+ {
+ cache: { paths: ["logs/", "binaries/"], untracked: true, key: 'global' },
+ rspec: {
+ script: "rspec",
+ cache: { paths: ["test/"], untracked: false, key: 'local' }
+ }
+ })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first[:cache]).to eq([
- paths: ["test/"],
- untracked: false,
- key: 'local',
- policy: 'pull-push',
- when: 'on_success'
- ])
+ expect(rspec_build[:cache]).to eq(
+ [
+ paths: ["test/"],
+ untracked: false,
+ key: 'local',
+ policy: 'pull-push',
+ when: 'on_success'
+ ])
end
end
describe "Artifacts" do
it "returns artifacts when defined" do
- config = YAML.dump({
- image: "image:1.0",
- services: ["mysql"],
- before_script: ["pwd"],
- rspec: {
- artifacts: {
- paths: ["logs/", "binaries/"],
- expose_as: "Exposed artifacts",
- untracked: true,
- name: "custom_name",
- expire_in: "7d"
- },
- script: "rspec"
- }
- })
+ config = YAML.dump(
+ {
+ image: "image:1.0",
+ services: ["mysql"],
+ before_script: ["pwd"],
+ rspec: {
+ artifacts: {
+ paths: ["logs/", "binaries/"],
+ expose_as: "Exposed artifacts",
+ untracked: true,
+ name: "custom_name",
+ expire_in: "7d"
+ },
+ script: "rspec"
+ }
+ })
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
+ rspec_build = config_processor.builds.find { |build| build[:name] == 'rspec' }
- expect(config_processor.stage_builds_attributes("test").size).to eq(1)
- expect(config_processor.stage_builds_attributes("test").first).to eq({
+ expect(rspec_build).to eq({
stage: "test",
stage_idx: 2,
name: "rspec",
@@ -1729,7 +1757,7 @@ module Gitlab
})
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
- builds = config_processor.stage_builds_attributes("test")
+ builds = config_processor.builds
expect(builds.size).to eq(1)
expect(builds.first[:options][:artifacts][:expire_in]).to eq('never')
@@ -1745,7 +1773,7 @@ module Gitlab
})
config_processor = Gitlab::Ci::YamlProcessor.new(config).execute
- builds = config_processor.stage_builds_attributes("test")
+ builds = config_processor.builds
expect(builds.size).to eq(1)
expect(builds.first[:options][:artifacts][:when]).to eq(when_state)
@@ -1778,7 +1806,7 @@ module Gitlab
- my/test/something
YAML
- attributes = Gitlab::Ci::YamlProcessor.new(config).execute.build_attributes('test')
+ attributes = Gitlab::Ci::YamlProcessor.new(config).execute.builds.find { |build| build[:name] == 'test' }
expect(attributes.dig(*%i[options artifacts exclude])).to eq(%w[my/test/something])
end
@@ -1819,7 +1847,7 @@ module Gitlab
end
it "returns release info" do
- expect(processor.stage_builds_attributes('release').first[:options])
+ expect(processor.builds.first[:options])
.to eq(config[:release].except(:stage, :only))
end
end
@@ -1833,7 +1861,7 @@ module Gitlab
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)).execute }
- let(:builds) { subject.stage_builds_attributes('deploy') }
+ let(:builds) { subject.builds }
context 'when a production environment is specified' do
let(:environment) { 'production' }
@@ -1943,7 +1971,7 @@ module Gitlab
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)).execute }
- let(:builds) { subject.stage_builds_attributes('deploy') }
+ let(:builds) { subject.builds }
context 'when no timeout was provided' do
it 'does not include job_timeout' do
@@ -2370,8 +2398,8 @@ module Gitlab
it 'returns a valid configuration and sets artifacts: true by default' do
expect(subject).to be_valid
- rspec = subject.build_attributes(:rspec)
- expect(rspec.dig(:options, :cross_dependencies)).to eq(
+ rspec_build = subject.builds.find { |build| build[:name] == 'rspec' }
+ expect(rspec_build.dig(:options, :cross_dependencies)).to eq(
[{ pipeline: '$THE_PIPELINE_ID', job: 'dependency-job', artifacts: true }]
)
end
@@ -2391,8 +2419,8 @@ module Gitlab
it 'returns a valid configuration and sets artifacts: true by default' do
expect(subject).to be_valid
- rspec = subject.build_attributes(:rspec)
- expect(rspec.dig(:options, :cross_dependencies)).to eq(
+ rspec_build = subject.builds.find { |build| build[:name] == 'rspec' }
+ expect(rspec_build.dig(:options, :cross_dependencies)).to eq(
[{ pipeline: '123', job: 'dependency-job', artifacts: true }]
)
end
@@ -2422,7 +2450,7 @@ module Gitlab
describe "Hidden jobs" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config).execute }
- subject { config_processor.stage_builds_attributes("test") }
+ subject { config_processor.builds }
shared_examples 'hidden_job_handling' do
it "doesn't create jobs that start with dot" do
@@ -2470,7 +2498,7 @@ module Gitlab
describe "YAML Alias/Anchor" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config).execute }
- subject { config_processor.stage_builds_attributes("build") }
+ subject { config_processor.builds }
shared_examples 'job_templates_handling' do
it "is correctly supported for jobs" do