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/config/entry/pull_policy_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config/entry/pull_policy_spec.rb87
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/pull_policy_spec.rb b/spec/lib/gitlab/ci/config/entry/pull_policy_spec.rb
new file mode 100644
index 00000000000..c35355b10c6
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/pull_policy_spec.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+RSpec.describe Gitlab::Ci::Config::Entry::PullPolicy do
+ let(:entry) { described_class.new(config) }
+
+ describe '#value' do
+ subject(:value) { entry.value }
+
+ context 'when config value is nil' do
+ let(:config) { nil }
+
+ it { is_expected.to be_nil }
+ end
+
+ context 'when retry value is an empty array' do
+ let(:config) { [] }
+
+ it { is_expected.to eq(nil) }
+ end
+
+ context 'when retry value is string' do
+ let(:config) { "always" }
+
+ it { is_expected.to eq(%w[always]) }
+ end
+
+ context 'when retry value is array' do
+ let(:config) { %w[always if-not-present] }
+
+ it { is_expected.to eq(%w[always if-not-present]) }
+ end
+ end
+
+ describe 'validation' do
+ subject(:valid?) { entry.valid? }
+
+ context 'when retry value is nil' do
+ let(:config) { nil }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'when retry value is an empty array' do
+ let(:config) { [] }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'when retry value is a hash' do
+ let(:config) { {} }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'when retry value is string' do
+ let(:config) { "always" }
+
+ it { is_expected.to eq(true) }
+
+ context 'when it is an invalid policy' do
+ let(:config) { "invalid" }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'when it is an empty string' do
+ let(:config) { "" }
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ context 'when retry value is array' do
+ let(:config) { %w[always if-not-present] }
+
+ it { is_expected.to eq(true) }
+
+ context 'when config contains an invalid policy' do
+ let(:config) { %w[always invalid] }
+
+ it { is_expected.to eq(false) }
+ end
+ end
+ end
+end