Skip to content

Commit 8e555b9

Browse files
authored
Merge pull request puppetlabs#105 from michaeltlombardi/ticket/master/FM-8342-test-on-localhost
(FM-8342) Run all tests on localhost
2 parents 04c98e8 + b58046d commit 8e555b9

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

spec/acceptance/init_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
describe 'service task' do
55
package_to_use = ''
66
before(:all) do
7-
unless ENV['TARGET_HOST'] == 'localhost'
8-
inventory_hash = inventory_hash_from_inventory_file
9-
add_feature_to_node(inventory_hash, 'puppet-agent', ENV['TARGET_HOST'])
10-
write_to_inventory_file(inventory_hash, 'inventory.yaml')
11-
end
7+
inventory_hash = inventory_hash_from_inventory_file
8+
target = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
9+
add_feature_to_node(inventory_hash, 'puppet-agent', target)
10+
write_to_inventory_file(inventory_hash, 'inventory.yaml')
1211
if os[:family] != 'windows'
1312
package_to_use = if os[:family] == 'redhat'
1413
'httpd'
@@ -18,6 +17,8 @@
1817
apply_manifest("package { \"#{package_to_use}\": ensure => present, }")
1918
else
2019
package_to_use = 'W32Time'
20+
params = { 'action' => 'enable', 'name' => package_to_use }
21+
run_bolt_task('service', params)
2122
params = { 'action' => 'start', 'name' => package_to_use }
2223
run_bolt_task('service', params)
2324
end

spec/acceptance/linux_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,12 @@
4040

4141
context 'when puppet-agent feature not available on target' do
4242
before(:all) do
43-
unless ENV['TARGET_HOST'] == 'localhost'
44-
inventory_hash = inventory_hash_from_inventory_file
45-
inventory_hash = remove_feature_from_node(inventory_hash, 'puppet-agent', ENV['TARGET_HOST'])
46-
write_to_inventory_file(inventory_hash, 'inventory.yaml')
47-
end
43+
target = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
44+
inventory_hash = remove_feature_from_node(inventory_hash_from_inventory_file, 'puppet-agent', target)
45+
write_to_inventory_file(inventory_hash, 'inventory.yaml')
4846
end
4947

5048
it 'enable action fails' do
51-
skip('Cannot mock inventory features during localhost acceptance testing') if ENV['TARGET_HOST'] == 'localhost'
5249
params = { 'action' => 'enable', 'name' => package_to_use }
5350
result = run_bolt_task('service', params, expect_failures: true)
5451
expect(result['result']).to include('status' => 'failure')
@@ -58,7 +55,6 @@
5855
end
5956

6057
it 'disable action fails' do
61-
skip('Cannot mock inventory features during localhost acceptance testing') if ENV['TARGET_HOST'] == 'localhost'
6258
params = { 'action' => 'disable', 'name' => package_to_use }
6359
result = run_bolt_task('service', params, expect_failures: true)
6460
expect(result['result']).to include('status' => 'failure')

spec/acceptance/windows_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
require 'spec_helper_acceptance'
33

44
describe 'windows service task', if: os[:family] == 'windows' do
5-
package_to_use = 'SessionEnv'
5+
package_to_use = 'W32Time'
6+
7+
before(:all) do
8+
# Ensure the service is enabled before interacting.
9+
run_bolt_task('service', 'action' => 'enable', 'name' => package_to_use)
10+
end
611

712
describe 'stop action' do
813
it "stop #{package_to_use}" do
@@ -39,15 +44,12 @@
3944

4045
context 'when puppet-agent feature not available on target' do
4146
before(:all) do
42-
unless ENV['TARGET_HOST'] == 'localhost'
43-
inventory_hash = inventory_hash_from_inventory_file
44-
inventory_hash = remove_feature_from_node(inventory_hash, 'puppet-agent', ENV['TARGET_HOST'])
45-
write_to_inventory_file(inventory_hash, 'inventory.yaml')
46-
end
47+
target = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
48+
inventory_hash = remove_feature_from_node(inventory_hash_from_inventory_file, 'puppet-agent', target)
49+
write_to_inventory_file(inventory_hash, 'inventory.yaml')
4750
end
4851

4952
it 'enable action fails' do
50-
skip('Cannot mock inventory features during localhost acceptance testing') if ENV['TARGET_HOST'] == 'localhost'
5153
params = { 'action' => 'enable', 'name' => package_to_use }
5254
result = run_bolt_task('service', params, expect_failures: true)
5355
expect(result['result']).to include('status' => 'failure')
@@ -57,7 +59,6 @@
5759
end
5860

5961
it 'disable action fails' do
60-
skip('Cannot mock inventory features during localhost acceptance testing') if ENV['TARGET_HOST'] == 'localhost'
6162
params = { 'action' => 'disable', 'name' => package_to_use }
6263
result = run_bolt_task('service', params, expect_failures: true)
6364
expect(result['result']).to include('status' => 'failure')

spec/spec_helper_acceptance.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
66
include PuppetLitmus
77

8-
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
8+
if targeting_localhost?
99
puts 'Running tests against this machine !'
10+
if File.exist?('inventory.yaml')
11+
inventory_hash = inventory_hash_from_inventory_file
12+
unless target_in_inventory?(inventory_hash, 'litmus_localhost')
13+
inventory_hash['groups'] = inventory_hash['groups'] | localhost_inventory_hash['groups']
14+
write_to_inventory_file(inventory_hash, 'inventory.yaml')
15+
end
16+
else
17+
write_to_inventory_file(localhost_inventory_hash, 'inventory.yaml')
18+
end
1019
if Gem.win_platform?
1120
set :backend, :cmd
1221
else

0 commit comments

Comments
 (0)