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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-27 18:06:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-27 18:06:45 +0300
commita98649b71085bcd21af674a47d6a746336c56a65 (patch)
tree1e518ce4f61a8d7260ba9d6d3b8db8906251d6a0 /spec/lib/gitlab/ci
parenta4484fd22dd0d055a10fe084b82349e42f7363e1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/ci')
-rw-r--r--spec/lib/gitlab/ci/ansi2json/style_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb12
-rw-r--r--spec/lib/gitlab/ci/config/entry/need_spec.rb168
-rw-r--r--spec/lib/gitlab/ci/config/entry/needs_spec.rb101
-rw-r--r--spec/lib/gitlab/ci/config/normalizer_spec.rb10
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb77
6 files changed, 338 insertions, 34 deletions
diff --git a/spec/lib/gitlab/ci/ansi2json/style_spec.rb b/spec/lib/gitlab/ci/ansi2json/style_spec.rb
index 5110c215415..ad05aa03e83 100644
--- a/spec/lib/gitlab/ci/ansi2json/style_spec.rb
+++ b/spec/lib/gitlab/ci/ansi2json/style_spec.rb
@@ -147,6 +147,10 @@ describe Gitlab::Ci::Ansi2json::Style do
[%w[1], %w[0], '', 'resets style from format bold'],
[%w[1 3], %w[0], '', 'resets style from format bold and italic'],
[%w[1 3 term-fg-l-red term-bg-yellow], %w[0], '', 'resets all formats and colors'],
+ # default foreground
+ [%w[31 42], %w[39], 'term-bg-green', 'set foreground from red to default leaving background unchanged'],
+ # default background
+ [%w[31 42], %w[49], 'term-fg-red', 'set background from green to default leaving foreground unchanged'],
# misc
[[], %w[1 30 42 3], 'term-fg-l-black term-bg-green term-bold term-italic', 'adds fg color, bg color and formats from no style'],
[%w[3 31], %w[23 1 43], 'term-fg-l-red term-bg-yellow term-bold', 'replaces format italic with bold and adds a yellow background']
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index b0e08e49d78..4d6245c2d86 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -93,7 +93,7 @@ describe Gitlab::Ci::Config::Entry::Job do
context 'when delayed job' do
context 'when start_in is specified' do
- let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
+ let(:config) { { script: 'echo', when: 'delayed', start_in: '1 week' } }
it { expect(entry).to be_valid }
end
@@ -232,11 +232,9 @@ describe Gitlab::Ci::Config::Entry::Job do
context 'when delayed job' do
context 'when start_in is specified' do
- let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
+ let(:config) { { script: 'echo', when: 'delayed', start_in: '1 week' } }
- it 'returns error about invalid type' do
- expect(entry).to be_valid
- end
+ it { expect(entry).to be_valid }
end
context 'when start_in is empty' do
@@ -257,8 +255,8 @@ describe Gitlab::Ci::Config::Entry::Job do
end
end
- context 'when start_in is longer than one day' do
- let(:config) { { when: 'delayed', start_in: '2 days' } }
+ context 'when start_in is longer than one week' do
+ let(:config) { { when: 'delayed', start_in: '8 days' } }
it 'returns error about exceeding the limit' do
expect(entry).not_to be_valid
diff --git a/spec/lib/gitlab/ci/config/entry/need_spec.rb b/spec/lib/gitlab/ci/config/entry/need_spec.rb
index d119e604900..92b71c5f6cc 100644
--- a/spec/lib/gitlab/ci/config/entry/need_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/need_spec.rb
@@ -5,31 +5,177 @@ require 'spec_helper'
describe ::Gitlab::Ci::Config::Entry::Need do
subject(:need) { described_class.new(config) }
- context 'when job is specified' do
- let(:config) { 'job_name' }
+ shared_examples 'job type' do
+ describe '#type' do
+ subject(:need_type) { need.type }
- describe '#valid?' do
- it { is_expected.to be_valid }
+ it { is_expected.to eq(:job) }
+ end
+ end
+
+ context 'with simple config' do
+ context 'when job is specified' do
+ let(:config) { 'job_name' }
+
+ describe '#valid?' do
+ it { is_expected.to be_valid }
+ end
+
+ describe '#value' do
+ it 'returns job needs configuration' do
+ expect(need.value).to eq(name: 'job_name', artifacts: true)
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'when need is empty' do
+ let(:config) { '' }
+
+ describe '#valid?' do
+ it { is_expected.not_to be_valid }
+ end
+
+ describe '#errors' do
+ it 'is returns an error about an empty config' do
+ expect(need.errors)
+ .to contain_exactly("job string config can't be blank")
+ end
+ end
+
+ it_behaves_like 'job type'
end
+ end
+
+ context 'with complex config' do
+ context 'with job name and artifacts true' do
+ let(:config) { { job: 'job_name', artifacts: true } }
+
+ describe '#valid?' do
+ it { is_expected.to be_valid }
+ end
+
+ describe '#value' do
+ it 'returns job needs configuration' do
+ expect(need.value).to eq(name: 'job_name', artifacts: true)
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'with job name and artifacts false' do
+ let(:config) { { job: 'job_name', artifacts: false } }
+
+ describe '#valid?' do
+ it { is_expected.to be_valid }
+ end
+
+ describe '#value' do
+ it 'returns job needs configuration' do
+ expect(need.value).to eq(name: 'job_name', artifacts: false)
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'with job name and artifacts nil' do
+ let(:config) { { job: 'job_name', artifacts: nil } }
- describe '#value' do
- it 'returns job needs configuration' do
- expect(need.value).to eq(name: 'job_name')
+ describe '#valid?' do
+ it { is_expected.to be_valid }
end
+
+ describe '#value' do
+ it 'returns job needs configuration' do
+ expect(need.value).to eq(name: 'job_name', artifacts: true)
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'without artifacts key' do
+ let(:config) { { job: 'job_name' } }
+
+ describe '#valid?' do
+ it { is_expected.to be_valid }
+ end
+
+ describe '#value' do
+ it 'returns job needs configuration' do
+ expect(need.value).to eq(name: 'job_name', artifacts: true)
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'when job name is empty' do
+ let(:config) { { job: '', artifacts: true } }
+
+ describe '#valid?' do
+ it { is_expected.not_to be_valid }
+ end
+
+ describe '#errors' do
+ it 'is returns an error about an empty config' do
+ expect(need.errors)
+ .to contain_exactly("job hash job can't be blank")
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'when job name is not a string' do
+ let(:config) { { job: :job_name, artifacts: false } }
+
+ describe '#valid?' do
+ it { is_expected.not_to be_valid }
+ end
+
+ describe '#errors' do
+ it 'is returns an error about job type' do
+ expect(need.errors)
+ .to contain_exactly('job hash job should be a string')
+ end
+ end
+
+ it_behaves_like 'job type'
+ end
+
+ context 'when job has unknown keys' do
+ let(:config) { { job: 'job_name', artifacts: false, some: :key } }
+
+ describe '#valid?' do
+ it { is_expected.not_to be_valid }
+ end
+
+ describe '#errors' do
+ it 'is returns an error about job type' do
+ expect(need.errors)
+ .to contain_exactly('job hash config contains unknown keys: some')
+ end
+ end
+
+ it_behaves_like 'job type'
end
end
- context 'when need is empty' do
- let(:config) { '' }
+ context 'when need config is not a string or a hash' do
+ let(:config) { :job_name }
describe '#valid?' do
it { is_expected.not_to be_valid }
end
describe '#errors' do
- it 'is returns an error about an empty config' do
+ it 'is returns an error about job type' do
expect(need.errors)
- .to contain_exactly("job config can't be blank")
+ .to contain_exactly('unknown strategy has an unsupported type')
end
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/needs_spec.rb b/spec/lib/gitlab/ci/config/entry/needs_spec.rb
index f4a76b52d30..b8b84b5efd2 100644
--- a/spec/lib/gitlab/ci/config/entry/needs_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/needs_spec.rb
@@ -51,9 +51,34 @@ describe ::Gitlab::Ci::Config::Entry::Needs do
end
end
end
+
+ context 'when wrong needs type is used' do
+ let(:config) { [{ job: 'job_name', artifacts: true, some: :key }] }
+
+ describe '#valid?' do
+ it { is_expected.not_to be_valid }
+ end
+
+ describe '#errors' do
+ it 'returns error about incorrect type' do
+ expect(needs.errors).to contain_exactly(
+ 'need config contains unknown keys: some')
+ end
+ end
+ end
end
describe '.compose!' do
+ shared_examples 'entry with descendant nodes' do
+ describe '#descendants' do
+ it 'creates valid descendant nodes' do
+ expect(needs.descendants.count).to eq 2
+ expect(needs.descendants)
+ .to all(be_an_instance_of(::Gitlab::Ci::Config::Entry::Need))
+ end
+ end
+ end
+
context 'when valid job entries composed' do
let(:config) { %w[first_job_name second_job_name] }
@@ -65,18 +90,80 @@ describe ::Gitlab::Ci::Config::Entry::Needs do
it 'returns key value' do
expect(needs.value).to eq(
job: [
- { name: 'first_job_name' },
- { name: 'second_job_name' }
+ { name: 'first_job_name', artifacts: true },
+ { name: 'second_job_name', artifacts: true }
]
)
end
end
- describe '#descendants' do
- it 'creates valid descendant nodes' do
- expect(needs.descendants.count).to eq 2
- expect(needs.descendants)
- .to all(be_an_instance_of(::Gitlab::Ci::Config::Entry::Need))
+ it_behaves_like 'entry with descendant nodes'
+ end
+
+ context 'with complex job entries composed' do
+ let(:config) do
+ [
+ { job: 'first_job_name', artifacts: true },
+ { job: 'second_job_name', artifacts: false }
+ ]
+ end
+
+ before do
+ needs.compose!
+ end
+
+ describe '#value' do
+ it 'returns key value' do
+ expect(needs.value).to eq(
+ job: [
+ { name: 'first_job_name', artifacts: true },
+ { name: 'second_job_name', artifacts: false }
+ ]
+ )
+ end
+ end
+
+ it_behaves_like 'entry with descendant nodes'
+ end
+
+ context 'with mixed job entries composed' do
+ let(:config) do
+ [
+ 'first_job_name',
+ { job: 'second_job_name', artifacts: false }
+ ]
+ end
+
+ before do
+ needs.compose!
+ end
+
+ describe '#value' do
+ it 'returns key value' do
+ expect(needs.value).to eq(
+ job: [
+ { name: 'first_job_name', artifacts: true },
+ { name: 'second_job_name', artifacts: false }
+ ]
+ )
+ end
+ end
+
+ it_behaves_like 'entry with descendant nodes'
+ end
+
+ context 'with empty config' do
+ let(:config) do
+ []
+ end
+
+ before do
+ needs.compose!
+ end
+
+ describe '#value' do
+ it 'returns empty value' do
+ expect(needs.value).to eq({})
end
end
end
diff --git a/spec/lib/gitlab/ci/config/normalizer_spec.rb b/spec/lib/gitlab/ci/config/normalizer_spec.rb
index bf880478387..db62fb7524d 100644
--- a/spec/lib/gitlab/ci/config/normalizer_spec.rb
+++ b/spec/lib/gitlab/ci/config/normalizer_spec.rb
@@ -105,7 +105,7 @@ describe Gitlab::Ci::Config::Normalizer do
context 'for needs' do
let(:expanded_job_attributes) do
expanded_job_names.map do |job_name|
- { name: job_name }
+ { name: job_name, extra: :key }
end
end
@@ -117,7 +117,7 @@ describe Gitlab::Ci::Config::Normalizer do
script: 'echo 1',
needs: {
job: [
- { name: job_name.to_s }
+ { name: job_name.to_s, extra: :key }
]
}
}
@@ -140,8 +140,8 @@ describe Gitlab::Ci::Config::Normalizer do
script: 'echo 1',
needs: {
job: [
- { name: job_name.to_s },
- { name: "other_job" }
+ { name: job_name.to_s, extra: :key },
+ { name: "other_job", extra: :key }
]
}
}
@@ -153,7 +153,7 @@ describe Gitlab::Ci::Config::Normalizer do
end
it "includes the regular job in dependencies" do
- expect(subject.dig(:final_job, :needs, :job)).to include(name: 'other_job')
+ expect(subject.dig(:final_job, :needs, :job)).to include(name: 'other_job', extra: :key)
end
end
end
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 5dc51f83b3c..ed2d97b1a38 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -1525,8 +1525,48 @@ module Gitlab
name: "test1",
options: { script: ["test"] },
needs_attributes: [
- { name: "build1" },
- { name: "build2" }
+ { name: "build1", artifacts: true },
+ { name: "build2", artifacts: true }
+ ],
+ when: "on_success",
+ allow_failure: false,
+ yaml_variables: []
+ )
+ end
+ end
+
+ context 'needs two builds' do
+ let(:needs) do
+ [
+ { job: 'parallel', artifacts: false },
+ { job: 'build1', artifacts: true },
+ 'build2'
+ ]
+ end
+
+ it "does create jobs with valid specification" do
+ expect(subject.builds.size).to eq(7)
+ expect(subject.builds[0]).to eq(
+ stage: "build",
+ stage_idx: 1,
+ name: "build1",
+ options: {
+ script: ["test"]
+ },
+ when: "on_success",
+ allow_failure: false,
+ yaml_variables: []
+ )
+ expect(subject.builds[4]).to eq(
+ stage: "test",
+ stage_idx: 2,
+ name: "test1",
+ options: { script: ["test"] },
+ needs_attributes: [
+ { name: "parallel 1/2", artifacts: false },
+ { name: "parallel 2/2", artifacts: false },
+ { name: "build1", artifacts: true },
+ { name: "build2", artifacts: true }
],
when: "on_success",
allow_failure: false,
@@ -1546,8 +1586,37 @@ module Gitlab
name: "test1",
options: { script: ["test"] },
needs_attributes: [
- { name: "parallel 1/2" },
- { name: "parallel 2/2" }
+ { name: "parallel 1/2", artifacts: true },
+ { name: "parallel 2/2", artifacts: true }
+ ],
+ when: "on_success",
+ allow_failure: false,
+ yaml_variables: []
+ )
+ end
+ end
+
+ context 'needs dependencies artifacts' do
+ let(:needs) do
+ [
+ "build1",
+ { job: "build2" },
+ { job: "parallel", artifacts: true }
+ ]
+ end
+
+ it "does create jobs with valid specification" do
+ expect(subject.builds.size).to eq(7)
+ expect(subject.builds[4]).to eq(
+ stage: "test",
+ stage_idx: 2,
+ name: "test1",
+ options: { script: ["test"] },
+ needs_attributes: [
+ { name: "build1", artifacts: true },
+ { name: "build2", artifacts: true },
+ { name: "parallel 1/2", artifacts: true },
+ { name: "parallel 2/2", artifacts: true }
],
when: "on_success",
allow_failure: false,