Skip to content

Commit 302e838

Browse files
refactor: Fix clippy warnings
1 parent a90663a commit 302e838

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

cloud-scanner-cli/src/aws_cloud_provider.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ mod tests {
431431
async fn get_cpu_usage_metrics_of_running_instance_should_return_right_number_of_data_points() {
432432
let aws: AwsCloudProvider = AwsCloudProvider::new("eu-west-1").await.unwrap();
433433
let res = aws
434-
.get_average_cpu_usage_of_last_10_minutes(&RUNNING_INSTANCE_ID)
434+
.get_average_cpu_usage_of_last_10_minutes(RUNNING_INSTANCE_ID)
435435
.await
436436
.unwrap();
437437
let datapoints = res.datapoints.unwrap();
438438
assert!(
439-
0 < datapoints.len() && datapoints.len() < 3,
439+
!datapoints.is_empty() && datapoints.len() < 3,
440440
"Strange number of datapoint returned for instance {}, is it really up ?. I was expecting 1 or 2 but got {} .\n {:#?}",
441441
&RUNNING_INSTANCE_ID,
442442
datapoints.len(),
@@ -476,15 +476,15 @@ mod tests {
476476
// This instance needs to be running for the test to pass
477477
let aws: AwsCloudProvider = AwsCloudProvider::new("eu-west-1").await.unwrap();
478478

479-
let avg_cpu_load = aws.get_average_cpu(&RUNNING_INSTANCE_ID).await.unwrap();
479+
let avg_cpu_load = aws.get_average_cpu(RUNNING_INSTANCE_ID).await.unwrap();
480480
assert_ne!(
481481
0 as f64, avg_cpu_load,
482482
"CPU load of instance {} is zero, is it really running ?",
483483
&RUNNING_INSTANCE_ID
484484
);
485485
println!("{:#?}", avg_cpu_load);
486-
assert!((0 as f64) < avg_cpu_load);
487-
assert!((100 as f64) > avg_cpu_load);
486+
assert!(0_f64 < avg_cpu_load);
487+
assert!(100_f64 > avg_cpu_load);
488488
}
489489

490490
#[tokio::test]

cloud-scanner-cli/src/boavizta_api_v1.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ mod tests {
377377
tags: Vec::new(),
378378
};
379379
let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
380-
let one_hour = 1.0 as f32;
380+
let one_hour = 1.0_f32;
381381
let res = api
382382
.get_raws_impacts(instance1, &one_hour, false)
383383
.await
@@ -404,7 +404,7 @@ mod tests {
404404
};
405405

406406
let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
407-
let one_hour = 1.0 as f32;
407+
let one_hour = 1.0_f32;
408408
let res = api.get_raws_impacts(hdd, &one_hour, true).await.unwrap();
409409

410410
let expected: serde_json::Value = serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_HDD).unwrap();
@@ -429,7 +429,7 @@ mod tests {
429429
};
430430

431431
let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
432-
let one_hour = 1.0 as f32;
432+
let one_hour = 1.0_f32;
433433
let res = api.get_raws_impacts(ssd, &one_hour, true).await.unwrap();
434434

435435
let expected: serde_json::Value =
@@ -470,11 +470,9 @@ mod tests {
470470
};
471471

472472
let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
473-
let one_hour = 1.0 as f32;
473+
let one_hour = 1.0_f32;
474474

475-
let mut instances: Vec<CloudResource> = Vec::new();
476-
instances.push(instance1);
477-
instances.push(instance1_1percent);
475+
let instances: Vec<CloudResource> = vec![instance1, instance1_1percent];
478476

479477
let inventory = Inventory {
480478
metadata: InventoryMetadata {
@@ -538,11 +536,8 @@ mod tests {
538536
tags: Vec::new(),
539537
};
540538

541-
let mut instances: Vec<CloudResource> = Vec::new();
542-
instances.push(instance1);
543-
instances.push(instance2);
544-
instances.push(instance3);
545-
let one_hour = 1.0 as f32;
539+
let instances: Vec<CloudResource> = vec![instance1, instance2, instance3];
540+
let one_hour = 1.0_f32;
546541

547542
let inventory = Inventory {
548543
metadata: InventoryMetadata {
@@ -590,7 +585,7 @@ mod tests {
590585

591586
let raw_impacts =
592587
Some(serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_M6GXLARGE_1HRS_FR).unwrap());
593-
let one_hour: f32 = 1 as f32;
588+
let one_hour: f32 = 1_f32;
594589
let cloud_resource_with_impacts: CloudResourceWithImpacts =
595590
boa_impacts_to_cloud_resource_with_impacts(&instance1, &raw_impacts, &one_hour);
596591
assert!(
@@ -636,7 +631,7 @@ mod tests {
636631

637632
let raw_impacts =
638633
Some(serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_M6GXLARGE_1HRS_FR_VERBOSE).unwrap());
639-
let one_hour: f32 = 1 as f32;
634+
let one_hour: f32 = 1_f32;
640635
let cloud_resource_with_impacts: CloudResourceWithImpacts =
641636
boa_impacts_to_cloud_resource_with_impacts(&instance1, &raw_impacts, &one_hour);
642637
assert!(

cloud-scanner-cli/src/model.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,10 @@ mod tests {
285285
},
286286
);
287287

288-
let mut instance1tags: Vec<CloudResourceTag> = Vec::new();
289-
instance1tags.push(CloudResourceTag {
288+
let instance1tags: Vec<CloudResourceTag> = vec![CloudResourceTag {
290289
key: "Name".to_string(),
291290
value: Some("App1".to_string()),
292-
});
291+
}];
293292

294293
let instance1: CloudResource = CloudResource {
295294
provider: CloudProvider::AWS,
@@ -302,8 +301,7 @@ mod tests {
302301
tags: instance1tags,
303302
};
304303

305-
assert_eq!(
306-
true,
304+
assert!(
307305
instance1.has_matching_tagmap(&filtertags),
308306
"Tags should match"
309307
);
@@ -317,9 +315,8 @@ mod tests {
317315
value: Some("OtherApp".to_string()),
318316
},
319317
);
320-
assert_eq!(
321-
false,
322-
instance1.has_matching_tagmap(&other_name_tag),
318+
assert!(
319+
!instance1.has_matching_tagmap(&other_name_tag),
323320
"Tags should not match"
324321
);
325322

@@ -332,9 +329,8 @@ mod tests {
332329
value: Some("PROD".to_string()),
333330
},
334331
);
335-
assert_eq!(
336-
false,
337-
instance1.has_matching_tagmap(&more_tags),
332+
assert!(
333+
!instance1.has_matching_tagmap(&more_tags),
338334
"Tags should not match"
339335
);
340336

@@ -347,16 +343,14 @@ mod tests {
347343
value: None,
348344
},
349345
);
350-
assert_eq!(
351-
false,
352-
instance1.has_matching_tagmap(&tag_without_val),
346+
assert!(
347+
!instance1.has_matching_tagmap(&tag_without_val),
353348
"Tag without a value should not match"
354349
);
355350

356351
// Trying an empty filter
357352
let empty_filter = HashMap::new();
358-
assert_eq!(
359-
true,
353+
assert!(
360354
instance1.has_matching_tagmap(&empty_filter),
361355
"Tags should match"
362356
);
@@ -372,8 +366,7 @@ mod tests {
372366
value: Some("whatever".to_string()),
373367
},
374368
);
375-
assert_eq!(
376-
true,
369+
assert!(
377370
instance1.has_matching_tagmap(&empty_filter),
378371
"Tags should match (i.e. we should ignore this invalid filter"
379372
);

0 commit comments

Comments
 (0)