Skip to content

Commit a12f122

Browse files
committed
(maint) use condensed litmus spec_helper_acceptance; fixup tests
1 parent dfa4c0c commit a12f122

File tree

3 files changed

+8
-59
lines changed

3 files changed

+8
-59
lines changed

spec/acceptance/emit_json_options_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{ :title => '--emit-json-stdout', :cmd_line => '--emit-json-stdout' }
5050
].each do |testcase|
5151
it "should emit JSON to stdout when using #{testcase[:title]}" do
52-
output = PuppetLitmus::PuppetHelpers.run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
52+
output = run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
5353
expect(JSON.parse(output)).to eq(expected)
5454
end
5555
end
@@ -61,7 +61,7 @@
6161
it "should write JSON to a file when using #{testcase[:title]}" do
6262
tmpfile = File.join(@remote_tmp_path, 'json_output.json')
6363
cmd = "puppet strings generate #{testcase[:cmd_line].gsub('TMPFILE', tmpfile)} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\""
64-
PuppetLitmus::PuppetHelpers.run_shell(cmd)
64+
run_shell(cmd)
6565
output = JSON.parse(file(tmpfile).content)
6666
expect(output).to eq(expected)
6767
end

spec/spec_helper_acceptance.rb

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,6 @@
1-
require 'serverspec'
2-
require 'puppet_litmus'
3-
include PuppetLitmus # rubocop:disable Style/MixinUsage This is fine
4-
5-
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
6-
puts 'Running tests against this machine !'
7-
if Gem.win_platform?
8-
set :backend, :cmd
9-
else
10-
set :backend, :exec
11-
end
12-
else
13-
# load inventory
14-
inventory_hash = inventory_hash_from_inventory_file
15-
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])
16-
17-
if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
18-
host = ENV['TARGET_HOST']
19-
set :backend, :docker
20-
set :docker_container, host
21-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
22-
set :backend, :ssh
23-
options = Net::SSH::Config.for(host)
24-
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
25-
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
26-
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
27-
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
28-
options[:verify_host_key] = Net::SSH::Verifiers::Never.new unless node_config.dig('ssh', 'host-key-check').nil?
29-
host = if ENV['TARGET_HOST'].include?(':')
30-
ENV['TARGET_HOST'].split(':').first
31-
else
32-
ENV['TARGET_HOST']
33-
end
34-
set :host, options[:host_name] || host
35-
set :ssh_options, options
36-
set :request_pty, true
37-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
38-
require 'winrm'
39-
40-
set :backend, :winrm
41-
set :os, family: 'windows'
42-
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
43-
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
44-
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
45-
46-
opts = {
47-
user: user,
48-
password: pass,
49-
endpoint: endpoint,
50-
operation_timeout: 300,
51-
}
52-
53-
winrm = WinRM::Connection.new opts
54-
Specinfra.configuration.winrm = winrm
55-
end
56-
end
1+
# frozen_string_literal: true
572

3+
require 'puppet_litmus'
584
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
5+
6+
PuppetLitmus.configure!

spec/spec_helper_acceptance_local.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
12
def sut_module_path(module_regex)
2-
modules = JSON.parse(PuppetLitmus::PuppetHelpers.run_shell('puppet module list --render-as json').stdout)
3+
modules = JSON.parse(run_shell('puppet module list --render-as json').stdout)
34
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex }
45
test_module_info.match(/\(([^)]*)\)/)[1]
56
end

0 commit comments

Comments
 (0)