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-12-16 15:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 15:07:43 +0300
commitd10a462fedbd7794a83abdba9b4526600f71de5b (patch)
tree4dbd21cb89013d9e07b05bac5101cd13585a8be5 /spec/lib/gitlab/ci
parent13867d66e92c2fd8962a126db4fbdc32891343c9 (diff)
Add latest changes from gitlab-org/gitlab@masterogolowinski-master-patch-80898
Diffstat (limited to 'spec/lib/gitlab/ci')
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb46
-rw-r--r--spec/lib/gitlab/ci/config_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb86
3 files changed, 129 insertions, 7 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index 6e077aa00d7..cc1ee63ff04 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -461,7 +461,8 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:unspecified) { double('unspecified', 'specified?' => false) }
let(:default) { double('default', '[]' => unspecified) }
- let(:deps) { double('deps', 'default' => default, '[]' => unspecified) }
+ let(:workflow) { double('workflow', 'has_rules?' => false) }
+ let(:deps) { double('deps', 'default' => default, '[]' => unspecified, 'workflow' => workflow) }
context 'when job config overrides default config' do
before do
@@ -492,6 +493,49 @@ describe Gitlab::Ci::Config::Entry::Job do
expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push')
end
end
+
+ context 'with workflow rules' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:name, :has_workflow_rules?, :only, :rules, :result) do
+ "uses default only" | false | nil | nil | { refs: %w[branches tags] }
+ "uses user only" | false | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | false | nil | [] | nil
+ "does not define only" | true | nil | nil | nil
+ "uses user only" | true | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | true | nil | [] | nil
+ end
+
+ with_them do
+ let(:config) { { script: 'ls', rules: rules, only: only }.compact }
+
+ it "#{name}" do
+ expect(workflow).to receive(:has_rules?) { has_workflow_rules? }
+
+ entry.compose!(deps)
+
+ expect(entry.only_value).to eq(result)
+ end
+ end
+ end
+
+ context 'when workflow rules is used' do
+ context 'when rules are used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, rules: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+
+ context 'when rules are not used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, only: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+ end
end
context 'when composed' do
diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb
index b039c572677..63a36995284 100644
--- a/spec/lib/gitlab/ci/config_spec.rb
+++ b/spec/lib/gitlab/ci/config_spec.rb
@@ -157,7 +157,7 @@ describe Gitlab::Ci::Config do
describe '.new' do
it 'raises error' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
@@ -367,7 +367,7 @@ describe Gitlab::Ci::Config do
end
it 'raises error TimeoutError' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 6083aac44f5..f61b28b06c8 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -28,6 +28,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"]
@@ -120,6 +121,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: { script: ["rspec"] },
interruptible: true,
allow_failure: false,
@@ -281,8 +283,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["rspec"] },
- only: { refs: ["branches"] },
- except: {} }] },
+ only: { refs: ["branches"] } }] },
{ name: "deploy",
index: 3,
builds:
@@ -293,8 +294,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["cap prod"] },
- only: { refs: ["tags"] },
- except: {} }] },
+ only: { refs: ["tags"] } }] },
{ name: ".post",
index: 4,
builds: [] }]
@@ -631,6 +631,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -662,6 +663,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -691,6 +693,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -716,6 +719,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1230,6 +1234,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1527,6 +1532,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1538,6 +1544,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1565,6 +1572,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1576,6 +1584,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: false },
@@ -1599,6 +1608,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: true },
@@ -1626,6 +1636,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1733,6 +1744,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "normal_job",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1778,6 +1790,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job1",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -1789,6 +1802,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job2",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -2235,6 +2249,70 @@ module Gitlab
it { is_expected.to be_nil }
end
end
+
+ describe '.new_with_validation_errors' do
+ subject { Gitlab::Ci::YamlProcessor.new_with_validation_errors(content) }
+
+ context 'when the YAML could not be parsed' do
+ let(:content) { YAML.dump('invalid: yaml: test') }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Invalid configuration format'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the tags parameter is invalid' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', tags: 'mysql' } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec:tags config should be an array of strings'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the configuration contains multiple keyword-syntax errors' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', bad_tags: 'mysql', rules: { wrong: 'format' } } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec config contains unknown keys: bad_tags', 'jobs:rspec rules should be an array of hashes'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when YAML content is empty' do
+ let(:content) { '' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Please provide content of .gitlab-ci.yml'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML contains an unknown alias' do
+ let(:content) { 'steps: *bad_alias' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Unknown alias: bad_alias'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML is valid' do
+ let(:content) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(true)
+ expect(subject.errors).to be_empty
+ expect(subject.content).to be_present
+ end
+ end
+ end
end
end
end