|
8 | 8 | RSpec.describe 'exercising a device provider' do
|
9 | 9 | let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' }
|
10 | 10 | let(:default_type_values) do
|
11 |
| - 'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF ' \ |
12 |
| - 'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 ' \ |
13 |
| - 'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"' |
| 11 | + 'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF '\ |
| 12 | + 'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 '\ |
| 13 | + 'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"' |
| 14 | + end |
| 15 | + |
| 16 | + before(:all) do |
| 17 | + if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.4.0') |
| 18 | + # work around https://tickets.puppetlabs.com/browse/PUP-8632 and https://tickets.puppetlabs.com/browse/PUP-9047 |
| 19 | + FileUtils.mkdir_p(File.expand_path('~/.puppetlabs/opt/puppet/cache/devices/the_node/state')) |
| 20 | + end |
14 | 21 | end
|
15 | 22 |
|
16 | 23 | describe 'using `puppet resource`' do
|
|
25 | 32 |
|
26 | 33 | it 'deals with canonicalized resources correctly' do
|
27 | 34 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
|
28 |
| - stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n' \ |
29 |
| - 'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \ |
| 35 | + stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n'\ |
| 36 | + 'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\ |
30 | 37 | 'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
|
31 |
| - expect(stdout_str).to match(/#{stdmatch}/) |
32 |
| - expect(status).not_to be_success |
| 38 | + expect(stdout_str).to match %r{#{stdmatch}} |
| 39 | + expect(status).to be_success |
33 | 40 | end
|
34 | 41 | end
|
35 | 42 |
|
|
38 | 45 |
|
39 | 46 | it 'deals with canonicalized resources correctly' do
|
40 | 47 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
|
41 |
| - stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n' \ |
42 |
| - 'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \ |
| 48 | + stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n'\ |
| 49 | + 'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\ |
43 | 50 | 'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
|
44 |
| - expect(stdout_str).to match(/#{stdmatch}/) |
| 51 | + expect(stdout_str).to match %r{#{stdmatch}} |
45 | 52 | expect(status).to be_success
|
46 | 53 | end
|
47 | 54 | end
|
|
54 | 61 | expected_values = 'device_provider { \'wibble\': \n\s+ensure => \'present\',\n\s+string => \'sample\',\n\#\s+string_ro => \'fixed\', # Read Only\n string_param => \'default value\',\n}'
|
55 | 62 | fiddle_deprecate_msg = "DL is deprecated, please use Fiddle\n"
|
56 | 63 | win32_deprecate_msg = ".*Struct layout is already defined for class Windows::ServiceStructs::SERVICE_STATUS_PROCESS.*\n"
|
57 |
| - expect(stdout_str.strip).to match(/\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z/) |
| 64 | + expect(stdout_str.strip).to match %r{\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z} |
58 | 65 | expect(status).to eq 0
|
59 | 66 | end
|
60 | 67 |
|
|
63 | 70 | expected_values = 'device_provider: |2\n\s+wibble:\n\s+ensure: :present\n\s+string: sample\n\s+string_ro: fixed\n\s+string_param: default value'
|
64 | 71 | fiddle_deprecate_msg = "DL is deprecated, please use Fiddle\n"
|
65 | 72 | win32_deprecate_msg = ".*Struct layout is already defined for class Windows::ServiceStructs::SERVICE_STATUS_PROCESS.*\n"
|
66 |
| - expect(stdout_str.strip).to match(/\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z/) |
| 73 | + expect(stdout_str.strip).to match %r{\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z} |
67 | 74 | expect(status).to eq 0
|
68 | 75 | end
|
69 | 76 |
|
70 | 77 | it 'deals with canonicalized resources correctly' do
|
71 | 78 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
|
72 | 79 | stdmatch = 'Notice: /Device_provider\[wibble\]/string: string changed \'sample\' to \'changed\''
|
73 |
| - expect(stdout_str).to match(/#{stdmatch}/) |
| 80 | + expect(stdout_str).to match %r{#{stdmatch}} |
74 | 81 | expect(status).to be_success
|
75 | 82 | end
|
76 | 83 | end
|
77 | 84 | end
|
78 | 85 |
|
79 | 86 | describe 'using `puppet device`' do
|
80 |
| - let(:common_args) { "#{super()} --target the_node" } |
| 87 | + let(:common_args) { super() + ' --target the_node' } |
81 | 88 | let(:device_conf) { Tempfile.new('device.conf') }
|
82 | 89 | let(:device_conf_content) do
|
83 |
| - <<~DEVICE_CONF |
84 |
| - [the_node] |
85 |
| - type test_device |
86 |
| - url file://#{device_credentials.path} |
87 |
| - DEVICE_CONF |
| 90 | + <<DEVICE_CONF |
| 91 | +[the_node] |
| 92 | +type test_device |
| 93 | +url file://#{device_credentials.path} |
| 94 | +DEVICE_CONF |
88 | 95 | end
|
89 | 96 | let(:device_credentials) { Tempfile.new('credentials.txt') }
|
90 | 97 | let(:device_credentials_content) do
|
91 |
| - <<~DEVICE_CREDS |
92 |
| - { |
93 |
| - username: foo |
94 |
| - secret: wibble |
95 |
| - } |
96 |
| - DEVICE_CREDS |
| 98 | + <<DEVICE_CREDS |
| 99 | +{ |
| 100 | + username: foo |
| 101 | + secret: wibble |
| 102 | +} |
| 103 | +DEVICE_CREDS |
| 104 | + end |
| 105 | + |
| 106 | + def is_device_apply_supported? |
| 107 | + Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0') |
97 | 108 | end
|
98 | 109 |
|
99 |
| - before do |
| 110 | + before(:each) do |
| 111 | + skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported? |
100 | 112 | device_conf.write(device_conf_content)
|
101 | 113 | device_conf.close
|
102 | 114 |
|
103 | 115 | device_credentials.write(device_credentials_content)
|
104 | 116 | device_credentials.close
|
105 | 117 | end
|
106 | 118 |
|
107 |
| - after do |
| 119 | + after(:each) do |
108 | 120 | device_conf.unlink
|
109 | 121 | device_credentials.unlink
|
110 | 122 | end
|
|
122 | 134 | f.close
|
123 | 135 |
|
124 | 136 | stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
|
125 |
| - expect(stdout_str).to match(/Compiled catalog for the_node/) |
126 |
| - expect(stdout_str).to match(/defined 'message' as 'foo'/) |
127 |
| - expect(stdout_str).not_to match(/Error:/) |
| 137 | + expect(stdout_str).to match %r{Compiled catalog for the_node} |
| 138 | + expect(stdout_str).to match %r{defined 'message' as 'foo'} |
| 139 | + expect(stdout_str).not_to match %r{Error:} |
128 | 140 | end
|
129 | 141 | end
|
130 | 142 |
|
|
134 | 146 | f.close
|
135 | 147 |
|
136 | 148 | stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
|
137 |
| - expect(stdout_str).not_to match(/Error:/) |
| 149 | + expect(stdout_str).not_to match %r{Error:} |
138 | 150 | expect(status).to eq 0
|
139 | 151 | end
|
140 | 152 | end
|
|
143 | 155 | it 'applies the catalog successfully' do
|
144 | 156 | Tempfile.create('fact_set') do |f|
|
145 | 157 | f.write 'device_provider{ "foo":' \
|
146 |
| - 'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", ' \ |
147 |
| - 'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, ' \ |
148 |
| - 'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }' |
| 158 | + 'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", '\ |
| 159 | + 'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, '\ |
| 160 | + 'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }' |
149 | 161 | f.close
|
150 | 162 |
|
151 | 163 | stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
|
152 |
| - expect(stdout_str).not_to match(/Error:/) |
| 164 | + expect(stdout_str).not_to match %r{Error:} |
153 | 165 | end
|
154 | 166 | end
|
155 | 167 | end
|
|
0 commit comments