@@ -193,8 +193,11 @@ mod tests {
193
193
194
194
#[ test]
195
195
fn parse_correct_addresses ( ) {
196
- let mut opts = Opts :: default ( ) ;
197
- opts. addresses = vec ! [ "127.0.0.1" . to_owned( ) , "192.168.0.0/30" . to_owned( ) ] ;
196
+ let opts = Opts {
197
+ addresses : vec ! [ "127.0.0.1" . to_owned( ) , "192.168.0.0/30" . to_owned( ) ] ,
198
+ ..Default :: default ( )
199
+ } ;
200
+
198
201
let ips = parse_addresses ( & opts) ;
199
202
200
203
assert_eq ! (
@@ -211,61 +214,84 @@ mod tests {
211
214
212
215
#[ test]
213
216
fn parse_correct_host_addresses ( ) {
214
- let mut opts = Opts :: default ( ) ;
215
- opts. addresses = vec ! [ "google.com" . to_owned( ) ] ;
217
+ let opts = Opts {
218
+ addresses : vec ! [ "google.com" . to_owned( ) ] ,
219
+ ..Default :: default ( )
220
+ } ;
221
+
216
222
let ips = parse_addresses ( & opts) ;
217
223
218
224
assert_eq ! ( ips. len( ) , 1 ) ;
219
225
}
220
226
221
227
#[ test]
222
228
fn parse_correct_and_incorrect_addresses ( ) {
223
- let mut opts = Opts :: default ( ) ;
224
- opts. addresses = vec ! [ "127.0.0.1" . to_owned( ) , "im_wrong" . to_owned( ) ] ;
229
+ let opts = Opts {
230
+ addresses : vec ! [ "127.0.0.1" . to_owned( ) , "im_wrong" . to_owned( ) ] ,
231
+ ..Default :: default ( )
232
+ } ;
233
+
225
234
let ips = parse_addresses ( & opts) ;
226
235
227
236
assert_eq ! ( ips, [ Ipv4Addr :: new( 127 , 0 , 0 , 1 ) , ] ) ;
228
237
}
229
238
230
239
#[ test]
231
240
fn parse_incorrect_addresses ( ) {
232
- let mut opts = Opts :: default ( ) ;
233
- opts. addresses = vec ! [ "im_wrong" . to_owned( ) , "300.10.1.1" . to_owned( ) ] ;
241
+ let opts = Opts {
242
+ addresses : vec ! [ "im_wrong" . to_owned( ) , "300.10.1.1" . to_owned( ) ] ,
243
+ ..Default :: default ( )
244
+ } ;
245
+
234
246
let ips = parse_addresses ( & opts) ;
235
247
236
248
assert ! ( ips. is_empty( ) ) ;
237
249
}
238
250
#[ test]
239
251
fn parse_hosts_file_and_incorrect_hosts ( ) {
240
252
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
241
- let mut opts = Opts :: default ( ) ;
242
- opts. addresses = vec ! [ "fixtures/hosts.txt" . to_owned( ) ] ;
253
+ let opts = Opts {
254
+ addresses : vec ! [ "fixtures/hosts.txt" . to_owned( ) ] ,
255
+ ..Default :: default ( )
256
+ } ;
257
+
243
258
let ips = parse_addresses ( & opts) ;
259
+
244
260
assert_eq ! ( ips. len( ) , 3 ) ;
245
261
}
246
262
247
263
#[ test]
248
264
fn parse_empty_hosts_file ( ) {
249
265
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
250
- let mut opts = Opts :: default ( ) ;
251
- opts. addresses = vec ! [ "fixtures/empty_hosts.txt" . to_owned( ) ] ;
266
+ let opts = Opts {
267
+ addresses : vec ! [ "fixtures/empty_hosts.txt" . to_owned( ) ] ,
268
+ ..Default :: default ( )
269
+ } ;
270
+
252
271
let ips = parse_addresses ( & opts) ;
272
+
253
273
assert_eq ! ( ips. len( ) , 0 ) ;
254
274
}
255
275
256
276
#[ test]
257
277
fn parse_naughty_host_file ( ) {
258
278
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
259
- let mut opts = Opts :: default ( ) ;
260
- opts. addresses = vec ! [ "fixtures/naughty_string.txt" . to_owned( ) ] ;
279
+ let opts = Opts {
280
+ addresses : vec ! [ "fixtures/naughty_string.txt" . to_owned( ) ] ,
281
+ ..Default :: default ( )
282
+ } ;
283
+
261
284
let ips = parse_addresses ( & opts) ;
285
+
262
286
assert_eq ! ( ips. len( ) , 0 ) ;
263
287
}
264
288
265
289
#[ test]
266
290
fn parse_duplicate_cidrs ( ) {
267
- let mut opts = Opts :: default ( ) ;
268
- opts. addresses = vec ! [ "79.98.104.0/21" . to_owned( ) , "79.98.104.0/24" . to_owned( ) ] ;
291
+ let opts = Opts {
292
+ addresses : vec ! [ "79.98.104.0/21" . to_owned( ) , "79.98.104.0/24" . to_owned( ) ] ,
293
+ ..Default :: default ( )
294
+ } ;
269
295
270
296
let ips = parse_addresses ( & opts) ;
271
297
@@ -285,9 +311,11 @@ mod tests {
285
311
286
312
#[ test]
287
313
fn resolver_args_google_dns ( ) {
288
- let mut opts = Opts :: default ( ) ;
289
314
// https://developers.google.com/speed/public-dns
290
- opts. resolver = Some ( "8.8.8.8,8.8.4.4" . to_owned ( ) ) ;
315
+ let opts = Opts {
316
+ resolver : Some ( "8.8.8.8,8.8.4.4" . to_owned ( ) ) ,
317
+ ..Default :: default ( )
318
+ } ;
291
319
292
320
let resolver = get_resolver ( & opts. resolver ) ;
293
321
let lookup = resolver. lookup_ip ( "www.example.com." ) . unwrap ( ) ;
0 commit comments