Skip to content

Commit f992867

Browse files
authored
Merge pull request #252 from UGent-DICT/feature/raise__errors_and_align
Get rid of all raise_error warnings in the tests and align errors a bit
2 parents 43297b0 + c8c0379 commit f992867

File tree

8 files changed

+38
-38
lines changed

8 files changed

+38
-38
lines changed

lib/puppet/provider/network_route/redhat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def self.format_file(_filename, providers)
7979
# Build routes
8080
providers.sort_by(&:name).each do |provider|
8181
[:network, :netmask, :gateway, :interface].each do |prop|
82-
raise Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil?
82+
raise Puppet::Error, "#{provider.name} is missing the required parameter '#{prop}'." if provider.send(prop).nil?
8383
end
8484
contents << if provider.network == 'default'
8585
"#{provider.network} via #{provider.gateway} dev #{provider.interface}"

lib/puppet/type/network_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def should_to_s(hash = @should)
137137
defaultto {}
138138

139139
validate do |value|
140-
raise ArgumentError, "#{self.class} requires a hash for the options property" unless value.is_a? Hash
140+
raise ArgumentError, "#{self.class} requires a hash for the 'options' parameter" unless value.is_a? Hash
141141
# provider.validate
142142
end
143143
end

lib/puppet/type/network_route.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
validate do |value|
2020
unless value == 'default'
2121
a = PuppetX::Voxpupuli::Utils.try { IPAddr.new(value) }
22-
raise("Invalid value for network: #{value}") unless a
22+
raise("Invalid value for parameter 'network': #{value}") unless a
2323
end
2424
end
2525
end
@@ -30,7 +30,7 @@
3030

3131
validate do |value|
3232
unless value.length <= 3 || PuppetX::Voxpupuli::Utils.try { IPAddr.new(value) }
33-
raise("Invalid value for argument netmask: #{value}")
33+
raise("Invalid value for parameter 'netmask': #{value}")
3434
end
3535
end
3636

@@ -45,7 +45,7 @@
4545
elsif PuppetX::Voxpupuli::Utils.try { IPAddr.new(value).ipv4? }
4646
IPAddr.new('255.255.255.255').mask(value).to_s
4747
else
48-
raise("Invalid value for argument netmask: #{value}")
48+
raise("Invalid value for parameter 'netmask': #{value}")
4949
end
5050
end
5151
end
@@ -58,7 +58,7 @@
5858
begin
5959
IPAddr.new(value)
6060
rescue ArgumentError
61-
raise("Invalid value for gateway: #{value}")
61+
raise("Invalid value for parameter 'gateway': #{value}")
6262
end
6363
end
6464
end

spec/unit/provider/network_config/interfaces_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def fixture_data(file)
142142
it 'with misplaced options should fail' do
143143
expect do
144144
described_class.parse_file('', "address 192.168.1.1\niface eth0 inet static\n")
145-
end.to raise_error
145+
end.to raise_error(%r{Malformed debian interfaces file})
146146
end
147147

148148
it 'with an option without a value should fail' do
149149
expect do
150150
described_class.parse_file('', "iface eth0 inet manual\naddress")
151-
end.to raise_error
151+
end.to raise_error(%r{Malformed debian interfaces file})
152152
end
153153
end
154154
end
@@ -313,13 +313,13 @@ def fixture_data(file)
313313
it 'fails if the family property is not defined' do
314314
lo_provider.unstub(:family)
315315
lo_provider.stubs(:family).returns nil
316-
expect { content }.to raise_exception
316+
expect { content }.to raise_exception(%r{does not have a family})
317317
end
318318

319319
it 'fails if the method property is not defined' do
320320
lo_provider.unstub(:method)
321321
lo_provider.stubs(:method).returns nil
322-
expect { content }.to raise_exception
322+
expect { content }.to raise_exception(%r{does not have a method})
323323
end
324324
end
325325

spec/unit/provider/network_route/redhat_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def fixture_data(file)
7272
it 'fails' do
7373
expect do
7474
described_class.parse_file('', "192.168.1.1/30 via\n")
75-
end.to raise_error
75+
end.to raise_error(%r{Malformed redhat route file})
7676
end
7777
end
7878
end
@@ -147,13 +147,13 @@ def fixture_data(file)
147147
it 'fails if the netmask property is not defined' do
148148
route2_provider.unstub(:netmask)
149149
route2_provider.stubs(:netmask).returns nil
150-
expect { content }.to raise_exception
150+
expect { content }.to raise_exception(%r{is missing the required parameter 'netmask'})
151151
end
152152

153153
it 'fails if the gateway property is not defined' do
154154
route2_provider.unstub(:gateway)
155155
route2_provider.stubs(:gateway).returns nil
156-
expect { content }.to raise_exception
156+
expect { content }.to raise_exception(%r{is missing the required parameter 'gateway'})
157157
end
158158
end
159159
end

spec/unit/provider/network_route/routes_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def fixture_data(file)
7777
it 'with missing options should fail' do
7878
expect do
7979
described_class.parse_file('', "192.168.1.1 255.255.255.0 172.16.0.1\n")
80-
end.to raise_error
80+
end.to raise_error(%r{Malformed debian routes file})
8181
end
8282
end
8383
end
@@ -126,13 +126,13 @@ def fixture_data(file)
126126
it 'fails if the netmask property is not defined' do
127127
route2_provider.unstub(:netmask)
128128
route2_provider.stubs(:netmask).returns nil
129-
expect { content }.to raise_exception
129+
expect { content }.to raise_exception(%r{is missing the required parameter 'netmask'})
130130
end
131131

132132
it 'fails if the gateway property is not defined' do
133133
route2_provider.unstub(:gateway)
134134
route2_provider.stubs(:gateway).returns nil
135-
expect { content }.to raise_exception
135+
expect { content }.to raise_exception(%r{is missing the required parameter 'gateway'})
136136
end
137137
end
138138
end
@@ -181,13 +181,13 @@ def fixture_data(file)
181181
it 'fails if the netmask property is not defined' do
182182
route2_provider.unstub(:netmask)
183183
route2_provider.stubs(:netmask).returns nil
184-
expect { content }.to raise_exception
184+
expect { content }.to raise_exception(%r{is missing the required parameter 'netmask'})
185185
end
186186

187187
it 'fails if the gateway property is not defined' do
188188
route2_provider.unstub(:gateway)
189189
route2_provider.stubs(:gateway).returns nil
190-
expect { content }.to raise_exception
190+
expect { content }.to raise_exception(%r{is missing the required parameter 'gateway'})
191191
end
192192
end
193193
end

spec/unit/type/network_config_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
end
8181
it 'fails when passed an IPv6 address' do
8282
pending('Not yet implemented')
83-
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address6) }.to raise_error
83+
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet, ipaddress: address6) }.to raise_error(%r{not a valid ipv4 address})
8484
end
8585
end
8686

@@ -90,20 +90,20 @@
9090
end
9191
it 'fails when passed an IPv4 address' do
9292
pending('Not yet implemented')
93-
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address4) }.to raise_error
93+
expect { Puppet::Type.type(:network_config).new(name: 'yay', family: :inet6, ipaddress: address4) }.to raise_error(%r{not a valid ipv6 address})
9494
end
9595
end
9696

9797
it 'fails if a malformed address is used' do
98-
expect { Puppet::Type.type(:network_config).new(name: 'yay', ipaddress: 'This is clearly not an IP address') }.to raise_error
98+
expect { Puppet::Type.type(:network_config).new(name: 'yay', ipaddress: 'This is clearly not an IP address') }.to raise_error(%r{requires a valid ipaddress})
9999
end
100100
end
101101

102102
describe 'netmask' do
103103
it 'fails if an invalid CIDR netmask is used' do
104104
expect do
105105
Puppet::Type.type(:network_config).new(name: 'yay', netmask: 'This is clearly not a netmask')
106-
end.to raise_error
106+
end.to raise_error(%r{requires a valid netmask})
107107
end
108108
end
109109

@@ -167,67 +167,67 @@
167167
it 'fails if an random string is passed' do
168168
expect do
169169
Puppet::Type.type(:network_config).new(name: 'yay', mtu: 'This is clearly not a mtu')
170-
end.to raise_error
170+
end.to raise_error(%r{must be a positive integer})
171171
end
172172

173173
it 'fails on values < 42' do
174174
expect do
175175
Puppet::Type.type(:network_config).new(name: 'yay', mtu: '41')
176-
end.to raise_error
176+
end.to raise_error(%r{is not in the valid mtu range})
177177
end
178178

179179
it 'fails on numeric values < 42' do
180180
expect do
181181
Puppet::Type.type(:network_config).new(name: 'yay', mtu: 41)
182-
end.to raise_error
182+
end.to raise_error(%r{is not in the valid mtu range})
183183
end
184184

185185
it 'fails on zero' do
186186
expect do
187187
Puppet::Type.type(:network_config).new(name: 'yay', mtu: '0')
188-
end.to raise_error
188+
end.to raise_error(%r{is not in the valid mtu range})
189189
end
190190

191191
it 'fails on numeric zero' do
192192
expect do
193193
Puppet::Type.type(:network_config).new(name: 'yay', mtu: 0)
194-
end.to raise_error
194+
end.to raise_error(%r{is not in the valid mtu range})
195195
end
196196

197197
it 'fails on values > 65536' do
198198
expect do
199199
Puppet::Type.type(:network_config).new(name: 'yay', mtu: '65537')
200-
end.to raise_error
200+
end.to raise_error(%r{is not in the valid mtu range})
201201
end
202202

203203
it 'fails on numeric values > 65536' do
204204
expect do
205205
Puppet::Type.type(:network_config).new(name: 'yay', mtu: 65_537)
206-
end.to raise_error
206+
end.to raise_error(%r{is not in the valid mtu range})
207207
end
208208

209209
it 'fails on negative values' do
210210
expect do
211211
Puppet::Type.type(:network_config).new(name: 'yay', mtu: '-1500')
212-
end.to raise_error
212+
end.to raise_error(%r{is not a valid mtu})
213213
end
214214

215215
it 'fails on negative numbers' do
216216
expect do
217217
Puppet::Type.type(:network_config).new(name: 'yay', mtu: -1500)
218-
end.to raise_error
218+
end.to raise_error(%r{is not in the valid mtu range})
219219
end
220220

221221
it 'fails on non-integer values' do
222222
expect do
223223
Puppet::Type.type(:network_config).new(name: 'yay', mtu: '1500.1')
224-
end.to raise_error
224+
end.to raise_error(%r{must be a positive integer})
225225
end
226226

227227
it 'fails on numeric non-integer values' do
228228
expect do
229229
Puppet::Type.type(:network_config).new(name: 'yay', mtu: 1500.1)
230-
end.to raise_error
230+
end.to raise_error(%r{must be a positive integer})
231231
end
232232
end
233233

@@ -240,7 +240,7 @@
240240
it 'fails on undefined values' do
241241
expect do
242242
Puppet::Type.type(:network_config).new(name: 'yay', mode: 'foo')
243-
end.to raise_error
243+
end.to raise_error(%r{Invalid value "foo". Valid values are})
244244
end
245245
it 'defaults to :raw' do
246246
expect(Puppet::Type.type(:network_config).new(name: 'yay')[:mode]).to eq(:raw)
@@ -262,7 +262,7 @@
262262
it 'fails if a non-hash is passed' do
263263
expect do
264264
Puppet::Type.type(:network_config).new(name: 'valid', options: 'geese')
265-
end.to raise_error
265+
end.to raise_error(%r{requires a hash for the 'options' parameter})
266266
end
267267
end
268268
end

spec/unit/type/network_route_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
it 'validates the network as an IP address' do
3737
expect do
3838
Puppet::Type.type(:network_route).new(name: '192.168.1.0/24', network: 'not an ip address', netmask: '255.255.255.0', gateway: '23.23.23.42', interface: 'eth0')
39-
end.to raise_error
39+
end.to raise_error(%r{Invalid value for parameter 'network'})
4040
end
4141
end
4242

4343
describe 'netmask' do
4444
it 'fails if an invalid netmask is used' do
4545
expect do
4646
Puppet::Type.type(:network_route).new(name: '192.168.1.0/24', network: '192.168.1.0', netmask: 'This is clearly not a netmask', gateway: '23.23.23.42', interface: 'eth0')
47-
end.to raise_error
47+
end.to raise_error(%r{Invalid value for parameter 'netmask'})
4848
end
4949

5050
it 'converts netmasks of the CIDR form' do
@@ -67,7 +67,7 @@
6767
it 'validates as an IP address' do
6868
expect do
6969
Puppet::Type.type(:network_route).new(name: '192.168.1.0/24', network: '192.168.1.0', netmask: '255.255.255.0', gateway: 'not an ip address', interface: 'eth0')
70-
end.to raise_error
70+
end.to raise_error(%r{Invalid value for parameter 'gateway'})
7171
end
7272
end
7373
end

0 commit comments

Comments
 (0)