Skip to content

Commit 89f6433

Browse files
author
Kevin Paulisse
committed
Spec coverage for --preserve-environments and related
1 parent 40b8f2c commit 89f6433

2 files changed

Lines changed: 175 additions & 15 deletions

File tree

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,7 @@ def initialize(options = {}, logger = nil)
4848
@facts_terminus = options.fetch(:facts_terminus, 'yaml')
4949

5050
create_structure
51-
52-
if options[:preserve_environments]
53-
install_directory_symlink(logger, File.join(options[:basedir], 'environments'), 'environments')
54-
options.fetch(:create_symlinks, %w(modules manifests)).each do |x|
55-
install_directory_symlink(logger, File.join(options[:basedir], x), x)
56-
end
57-
else
58-
if options[:environment]
59-
logger.warn '--environment is ignored unless --preserve-environment is used' unless logger.nil?
60-
end
61-
if options[:create_symlinks]
62-
logger.warn '--create-symlinks is ignored unless --preserve-environment is used' unless logger.nil?
63-
end
64-
install_directory_symlink(logger, options[:basedir])
65-
end
51+
create_symlinks(logger)
6652

6753
# These configurations are optional. Don't call the methods if parameters are nil.
6854
unless options[:puppetdb_url].nil?
@@ -84,6 +70,30 @@ def create_structure
8470
end
8571
end
8672

73+
# Create symlinks.
74+
#
75+
# If the `--preserve-environments` option is used, the `environments` directory, plus `modules` and
76+
# `manifests` symlinks are created. Otherwise, `environments/production` is pointed at the base
77+
# directory.
78+
#
79+
# @param logger [Logger] Logger object
80+
def create_symlinks(logger = nil)
81+
if @options[:preserve_environments]
82+
install_directory_symlink(logger, File.join(@options[:basedir], 'environments'), 'environments')
83+
@options.fetch(:create_symlinks, %w(modules manifests)).each do |x|
84+
install_directory_symlink(logger, File.join(@options[:basedir], x), x)
85+
end
86+
else
87+
if @options[:environment]
88+
logger.warn '--environment is ignored unless --preserve-environments is used' unless logger.nil?
89+
end
90+
if @options[:create_symlinks]
91+
logger.warn '--create-symlinks is ignored unless --preserve-environments is used' unless logger.nil?
92+
end
93+
install_directory_symlink(logger, @options[:basedir])
94+
end
95+
end
96+
8797
# Install puppetdb.conf file in temporary directory
8898
# @param server_urls [String] String for server_urls in puppetdb.conf
8999
# @param server_url_timeout [Fixnum] Value for server_url_timeout in puppetdb.conf

spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,156 @@
2525
end
2626
end
2727

28+
describe '#create_symlinks' do
29+
before(:each) do
30+
@described_object = described_class.allocate
31+
end
32+
33+
context 'with --preserve-environmentss' do
34+
context 'with --create-symlinks' do
35+
it 'should install environment + custom symlinks' do
36+
@described_object.instance_variable_set(
37+
'@options',
38+
basedir: '/tmp/basedir',
39+
preserve_environments: true,
40+
create_symlinks: %w(foo bar)
41+
)
42+
43+
expect(@described_object)
44+
.to receive(:install_directory_symlink)
45+
.with(nil, '/tmp/basedir/environments', 'environments')
46+
47+
expect(@described_object)
48+
.to receive(:install_directory_symlink)
49+
.with(nil, '/tmp/basedir/foo', 'foo')
50+
51+
expect(@described_object)
52+
.to receive(:install_directory_symlink)
53+
.with(nil, '/tmp/basedir/bar', 'bar')
54+
55+
expect { @described_object.send(:create_symlinks) }.not_to raise_error
56+
end
57+
end
58+
59+
context 'without --create-symlinks' do
60+
it 'should install environment + default symlinks' do
61+
@described_object.instance_variable_set(
62+
'@options',
63+
basedir: '/tmp/basedir',
64+
preserve_environments: true
65+
)
66+
67+
expect(@described_object)
68+
.to receive(:install_directory_symlink)
69+
.with(nil, '/tmp/basedir/environments', 'environments')
70+
71+
expect(@described_object)
72+
.to receive(:install_directory_symlink)
73+
.with(nil, '/tmp/basedir/manifests', 'manifests')
74+
75+
expect(@described_object)
76+
.to receive(:install_directory_symlink)
77+
.with(nil, '/tmp/basedir/modules', 'modules')
78+
79+
expect { @described_object.send(:create_symlinks) }.not_to raise_error
80+
end
81+
end
82+
end
83+
84+
context 'without --preserve-environmentss' do
85+
context 'with --create-symlinks' do
86+
context 'with logger' do
87+
it 'should log a warning message and install default symlink' do
88+
logger = double('Logger')
89+
expect(logger).to receive(:warn).with('--create-symlinks is ignored unless --preserve-environments is used')
90+
91+
@described_object.instance_variable_set(
92+
'@options',
93+
basedir: '/tmp/basedir',
94+
create_symlinks: %w(foo bar)
95+
)
96+
97+
expect(@described_object)
98+
.to receive(:install_directory_symlink)
99+
.with(logger, '/tmp/basedir')
100+
101+
expect { @described_object.send(:create_symlinks, logger) }.not_to raise_error
102+
end
103+
end
104+
105+
context 'without logger' do
106+
it 'should install directory symlink' do
107+
@described_object.instance_variable_set(
108+
'@options',
109+
basedir: '/tmp/basedir',
110+
create_symlinks: %w(foo bar)
111+
)
112+
113+
expect(@described_object)
114+
.to receive(:install_directory_symlink)
115+
.with(nil, '/tmp/basedir')
116+
117+
expect { @described_object.send(:create_symlinks) }.not_to raise_error
118+
end
119+
end
120+
end
121+
122+
context 'with --environment' do
123+
context 'with logger' do
124+
it 'should log a warning message and install default symlink' do
125+
logger = double('Logger')
126+
expect(logger).to receive(:warn).with('--environment is ignored unless --preserve-environments is used')
127+
128+
@described_object.instance_variable_set(
129+
'@options',
130+
basedir: '/tmp/basedir',
131+
environment: 'baz'
132+
)
133+
134+
expect(@described_object)
135+
.to receive(:install_directory_symlink)
136+
.with(logger, '/tmp/basedir')
137+
138+
expect { @described_object.send(:create_symlinks, logger) }.not_to raise_error
139+
end
140+
end
141+
142+
context 'without logger' do
143+
it 'should install default symlink' do
144+
@described_object.instance_variable_set(
145+
'@options',
146+
basedir: '/tmp/basedir',
147+
environment: 'baz'
148+
)
149+
150+
expect(@described_object)
151+
.to receive(:install_directory_symlink)
152+
.with(nil, '/tmp/basedir')
153+
154+
expect { @described_object.send(:create_symlinks) }.not_to raise_error
155+
end
156+
end
157+
end
158+
159+
context 'without --create-symlinks or --environment' do
160+
it 'should install directory symlink' do
161+
logger = double('Logger')
162+
163+
@described_object.instance_variable_set(
164+
'@options',
165+
basedir: '/tmp/basedir'
166+
)
167+
168+
expect(@described_object)
169+
.to receive(:install_directory_symlink)
170+
.with(logger, '/tmp/basedir')
171+
172+
expect { @described_object.send(:create_symlinks, logger) }.not_to raise_error
173+
end
174+
end
175+
end
176+
end
177+
28178
describe '#install_directory_symlink' do
29179
it 'should create properly pointed symlink' do
30180
options = {

0 commit comments

Comments
 (0)