2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Config::Entry::Factory do
|
2016-06-16 23:09:34 +05:30
|
|
|
describe '#create!' do
|
2020-06-23 00:09:42 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
stub_const('Commands', Class.new(Gitlab::Config::Entry::Node))
|
|
|
|
Commands.class_eval do
|
2020-06-23 00:09:42 +05:30
|
|
|
include Gitlab::Config::Entry::Validatable
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
validations do
|
|
|
|
validates :config, array_of_strings: true
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:entry) { Commands }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:factory) { described_class.new(entry) }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when setting a concrete value' do
|
2016-06-16 23:09:34 +05:30
|
|
|
it 'creates entry with valid value' do
|
|
|
|
entry = factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-06-16 23:09:34 +05:30
|
|
|
.create!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry.value).to eq %w(ls pwd)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting description' do
|
2019-09-30 21:07:59 +05:30
|
|
|
before do
|
|
|
|
factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-06-16 23:09:34 +05:30
|
|
|
.with(description: 'test description')
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures description' do
|
|
|
|
expect(factory.description).to eq 'test description'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates entry with description' do
|
|
|
|
entry = factory.create!
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry.value).to eq %w(ls pwd)
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(entry.description).to eq 'test description'
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'when setting inherit' do
|
|
|
|
before do
|
|
|
|
factory
|
|
|
|
.value(%w(ls pwd))
|
|
|
|
.with(inherit: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes object inheritable' do
|
|
|
|
expect(factory.inheritable?).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when setting key' do
|
|
|
|
it 'creates entry with custom key' do
|
|
|
|
entry = factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-09-13 17:45:13 +05:30
|
|
|
.with(key: 'test key')
|
2016-08-24 12:49:21 +05:30
|
|
|
.create!
|
|
|
|
|
|
|
|
expect(entry.key).to eq 'test key'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting a parent' do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:object) { Object.new }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
it 'creates entry with valid parent' do
|
|
|
|
entry = factory
|
2016-09-13 17:45:13 +05:30
|
|
|
.value('ls')
|
|
|
|
.with(parent: object)
|
2016-08-24 12:49:21 +05:30
|
|
|
.create!
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(entry.parent).to eq object
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when not setting a value' do
|
2016-06-16 23:09:34 +05:30
|
|
|
it 'raises error' do
|
|
|
|
expect { factory.create! }.to raise_error(
|
2019-02-15 15:39:39 +05:30
|
|
|
Gitlab::Config::Entry::Factory::InvalidFactory
|
2016-06-16 23:09:34 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when creating entry with nil value' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'creates an unspecified entry' do
|
2016-06-16 23:09:34 +05:30
|
|
|
entry = factory
|
2016-09-13 17:45:13 +05:30
|
|
|
.value(nil)
|
2016-06-16 23:09:34 +05:30
|
|
|
.create!
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(entry)
|
2017-08-17 22:00:37 +05:30
|
|
|
.not_to be_specified
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
context 'when passing metadata' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:entry) { spy('entry') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
it 'passes metadata as a parameter' do
|
|
|
|
factory
|
|
|
|
.value('some value')
|
|
|
|
.metadata(some: 'hash')
|
|
|
|
.create!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry).to have_received(:new)
|
2016-09-13 17:45:13 +05:30
|
|
|
.with('some value', { some: 'hash' })
|
|
|
|
end
|
|
|
|
end
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
context 'when setting deprecation information' do
|
|
|
|
it 'passes deprecation as a parameter' do
|
|
|
|
entry = factory
|
|
|
|
.value('some value')
|
|
|
|
.with(deprecation: { deprecated: '10.0', warning: '10.1', removed: '11.0', documentation: 'docs' })
|
|
|
|
.create!
|
|
|
|
|
|
|
|
expect(entry.deprecation).to eq({ deprecated: '10.0', warning: '10.1', removed: '11.0', documentation: 'docs' })
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|