summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry')
-rw-r--r--spec/lib/gitlab/ci/config/entry/default_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/root_spec.rb9
-rw-r--r--spec/lib/gitlab/ci/config/entry/workflow_spec.rb76
3 files changed, 81 insertions, 6 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/default_spec.rb b/spec/lib/gitlab/ci/config/entry/default_spec.rb
index a0856037340..dad4f408e50 100644
--- a/spec/lib/gitlab/ci/config/entry/default_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/default_spec.rb
@@ -13,7 +13,7 @@ describe Gitlab::Ci::Config::Entry::Default do
# that we know that we don't want to inherit
# as they do not have sense in context of Default
let(:ignored_inheritable_columns) do
- %i[default include variables stages types]
+ %i[default include variables stages types workflow]
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb
index 3877eec8887..43bd53b780f 100644
--- a/spec/lib/gitlab/ci/config/entry/root_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb
@@ -18,9 +18,8 @@ describe Gitlab::Ci::Config::Entry::Root do
#
# The purpose of `Root` is have only globally defined configuration.
expect(described_class.nodes.keys)
- .to match_array(%i[before_script image services
- after_script variables cache
- stages types include default])
+ .to match_array(%i[before_script image services after_script
+ variables cache stages types include default workflow])
end
end
end
@@ -50,7 +49,7 @@ describe Gitlab::Ci::Config::Entry::Root do
end
it 'creates node object for each entry' do
- expect(root.descendants.count).to eq 10
+ expect(root.descendants.count).to eq 11
end
it 'creates node object using valid class' do
@@ -203,7 +202,7 @@ describe Gitlab::Ci::Config::Entry::Root do
describe '#nodes' do
it 'instantizes all nodes' do
- expect(root.descendants.count).to eq 10
+ expect(root.descendants.count).to eq 11
end
it 'contains unspecified nodes' do
diff --git a/spec/lib/gitlab/ci/config/entry/workflow_spec.rb b/spec/lib/gitlab/ci/config/entry/workflow_spec.rb
new file mode 100644
index 00000000000..f2832b94bf0
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/workflow_spec.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Ci::Config::Entry::Workflow do
+ let(:factory) { Gitlab::Config::Entry::Factory.new(described_class).value(rules_hash) }
+ let(:config) { factory.create! }
+
+ describe 'validations' do
+ context 'when work config value is a string' do
+ let(:rules_hash) { 'build' }
+
+ describe '#valid?' do
+ it 'is invalid' do
+ expect(config).not_to be_valid
+ end
+
+ it 'attaches an error specifying that workflow should point to a hash' do
+ expect(config.errors).to include('workflow config should be a hash')
+ end
+ end
+
+ describe '#value' do
+ it 'returns the invalid configuration' do
+ expect(config.value).to eq(rules_hash)
+ end
+ end
+ end
+
+ context 'when work config value is a hash' do
+ let(:rules_hash) { { rules: [{ if: '$VAR' }] } }
+
+ describe '#valid?' do
+ it 'is valid' do
+ expect(config).to be_valid
+ end
+
+ it 'attaches no errors' do
+ expect(config.errors).to be_empty
+ end
+ end
+
+ describe '#value' do
+ it 'returns the config' do
+ expect(config.value).to eq(rules_hash)
+ end
+ end
+
+ context 'with an invalid key' do
+ let(:rules_hash) { { trash: [{ if: '$VAR' }] } }
+
+ describe '#valid?' do
+ it 'is invalid' do
+ expect(config).not_to be_valid
+ end
+
+ it 'attaches an error specifying the unknown key' do
+ expect(config.errors).to include('workflow config contains unknown keys: trash')
+ end
+ end
+
+ describe '#value' do
+ it 'returns the invalid configuration' do
+ expect(config.value).to eq(rules_hash)
+ end
+ end
+ end
+ end
+ end
+
+ describe '.default' do
+ it 'is nil' do
+ expect(described_class.default).to be_nil
+ end
+ end
+end