Skip to content

Commit b024941

Browse files
authored
Merge pull request #92 from github/kpaulisse-environment-without-preserve
Bump version and changelog for #86
2 parents 510b6b4 + 8ec4fb6 commit b024941

File tree

8 files changed

+70
-22
lines changed

8 files changed

+70
-22
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
1.0.3

doc/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
</tr>
99
</thead><tbody>
1010
<tr valign=top>
11+
<td>1.0.3</td>
12+
<td>2017-03-15</td>
13+
<td>
14+
<li><a href="https://github.com/github/octocatalog-diff/pull/86">#86</a>: Ability to use `--environment` without `--preserve-environments`</li>
15+
</td>
16+
</tr>
17+
<tr valign=top>
1118
<td>1.0.2</td>
1219
<td>2017-03-08</td>
1320
<td>

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ def create_symlinks(logger = nil)
8484
install_directory_symlink(logger, File.join(@options[:basedir], x), x)
8585
end
8686
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]
87+
if @options[:create_symlinks] && @options[:environment]
88+
unless logger.nil?
89+
logger.warn '--create-symlinks with --environment ignored unless --preserve-environments is used'
90+
end
91+
elsif @options[:create_symlinks]
9192
logger.warn '--create-symlinks is ignored unless --preserve-environments is used' unless logger.nil?
93+
elsif @options[:environment]
94+
return install_directory_symlink(logger, @options[:basedir], "environments/#{@options[:environment]}")
9295
end
9396
install_directory_symlink(logger, @options[:basedir])
9497
end
@@ -178,6 +181,7 @@ def install_fact_file(logger, options)
178181
def install_directory_symlink(logger, dir, target = 'environments/production')
179182
raise ArgumentError, "Called install_directory_symlink with #{dir.class} argument" unless dir.is_a?(String)
180183
raise Errno::ENOENT, "Specified directory #{dir} doesn't exist" unless File.directory?(dir)
184+
181185
symlink_target = File.join(@tempdir, target)
182186

183187
if target =~ %r{/}
@@ -330,7 +334,7 @@ def install_ssl_client_password(logger, password)
330334
end
331335

332336
def environment
333-
@options[:preserve_environments] ? @options.fetch(:environment, 'production') : 'production'
337+
@options.fetch(:environment, 'production')
334338
end
335339
end
336340
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def puppet_command
7878
# Add environment - only make this variable if preserve_environments is used.
7979
# If preserve_environments is not used, the hard-coded 'production' here matches
8080
# up with the symlink created under the temporary directory structure.
81-
environ = @options[:preserve_environments] ? @options.fetch(:environment, 'production') : 'production'
81+
environ = @options.fetch(:environment, 'production')
8282
cmdline << "--environment=#{Shellwords.escape(environ)}"
8383

8484
# For people who aren't running hiera, a hiera-config will not be generated when @options[:hiera_config]

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def compilation_dir
8080

8181
# Environment used to compile catalog
8282
def environment
83-
@opts[:preserve_environments] ? @opts.fetch(:environment, 'production') : 'production'
83+
@opts.fetch(:environment, 'production')
8484
end
8585

8686
private

spec/octocatalog-diff/integration/preserve_environments_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'-n', 'rspec-node.github.net',
4141
'--environment', 'asdfgh',
4242
'--to-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/default-catalog-v4.json'),
43-
'--hiera-config', 'environments/production/config/hiera.yaml',
43+
'--hiera-config', 'config/hiera.yaml',
4444
'--hiera-path-strip', '/var/lib/puppet', '--no-parallel'
4545
]
4646
)
@@ -50,10 +50,6 @@
5050
expect(@result.exitcode).to eq(0), OctocatalogDiff::Integration.format_exception(@result)
5151
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
5252
end
53-
54-
it 'should log warning about --environment being useless in this context' do
55-
expect(@result.logs).to match(/WARN -- : --environment is ignored unless --preserve-environments is used/)
56-
end
5753
end
5854

5955
context 'with --create-symlinks set' do

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

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
context 'with --create-symlinks' do
8888
context 'with logger' do
8989
it 'should log a warning message and install default symlink' do
90-
logger = double('Logger')
90+
logger, = OctocatalogDiff::Spec.setup_logger
9191
expect(logger).to receive(:warn).with('--create-symlinks is ignored unless --preserve-environments is used')
9292

9393
@described_object.instance_variable_set(
@@ -121,15 +121,18 @@
121121
end
122122
end
123123

124-
context 'with --environment' do
124+
context 'with --create-symlinks and --environment' do
125125
context 'with logger' do
126126
it 'should log a warning message and install default symlink' do
127-
logger = double('Logger')
128-
expect(logger).to receive(:warn).with('--environment is ignored unless --preserve-environments is used')
127+
logger, = OctocatalogDiff::Spec.setup_logger
128+
expect(logger).to receive(:warn).with(
129+
'--create-symlinks with --environment ignored unless --preserve-environments is used'
130+
)
129131

130132
@described_object.instance_variable_set(
131133
'@options',
132134
basedir: '/tmp/basedir',
135+
create_symlinks: %w(foo bar),
133136
environment: 'baz'
134137
)
135138

@@ -146,6 +149,7 @@
146149
@described_object.instance_variable_set(
147150
'@options',
148151
basedir: '/tmp/basedir',
152+
create_symlinks: %w(foo bar),
149153
environment: 'baz'
150154
)
151155

@@ -157,10 +161,45 @@
157161
end
158162
end
159163
end
164+
context 'with --environment' do
165+
context 'with logger' do
166+
it 'should install a symlink to the given environment' do
167+
logger, = OctocatalogDiff::Spec.setup_logger
168+
169+
@described_object.instance_variable_set(
170+
'@options',
171+
basedir: '/tmp/basedir',
172+
environment: 'baz'
173+
)
174+
175+
expect(@described_object)
176+
.to receive(:install_directory_symlink)
177+
.with(logger, '/tmp/basedir', 'environments/baz')
178+
179+
expect { @described_object.send(:create_symlinks, logger) }.not_to raise_error
180+
end
181+
end
182+
183+
context 'without logger' do
184+
it 'should install default symlink' do
185+
@described_object.instance_variable_set(
186+
'@options',
187+
basedir: '/tmp/basedir',
188+
environment: 'baz'
189+
)
190+
191+
expect(@described_object)
192+
.to receive(:install_directory_symlink)
193+
.with(nil, '/tmp/basedir', 'environments/baz')
194+
195+
expect { @described_object.send(:create_symlinks) }.not_to raise_error
196+
end
197+
end
198+
end
160199

161200
context 'without --create-symlinks or --environment' do
162201
it 'should install directory symlink' do
163-
logger = double('Logger')
202+
logger, = OctocatalogDiff::Spec.setup_logger
164203

165204
@described_object.instance_variable_set(
166205
'@options',

spec/octocatalog-diff/tests/catalog/computed_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,19 @@
422422
context 'when preserve_environments is not set' do
423423
context 'and environment is specified' do
424424
it 'should return without raising error when directory exists' do
425-
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
425+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
426+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/custom').and_return(true)
426427
described_object = described_class.allocate
427-
described_object.instance_variable_set('@opts', environment: 'nope')
428+
described_object.instance_variable_set('@opts', environment: 'custom')
428429
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
429430
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
430431
end
431432

432433
it 'should raise Errno::ENOENT when directory does not exist' do
433-
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
434+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
435+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/custom').and_return(false)
434436
described_object = described_class.allocate
435-
described_object.instance_variable_set('@opts', environment: 'yup')
437+
described_object.instance_variable_set('@opts', environment: 'custom')
436438
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
437439
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
438440
end

0 commit comments

Comments
 (0)