Skip to content

Commit

Permalink
Refine input type from Any to ToString
Browse files Browse the repository at this point in the history
Signed-off-by: posutsai <posutsai@gmail.com>
  • Loading branch information
posutsai committed Sep 2, 2024
1 parent 7b35e93 commit afbe94d
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tests/contest/contest/src/tests/cgroups/cpu/v1.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::any::Any;
use std::fs;
use std::path::Path;

use anyhow::{Context, Result};
use libcgroups::common;
use num_cpus;
use std::string::ToString;
use test_framework::{test_result, ConditionalTest, TestGroup, TestResult};
use tracing::debug;

Expand Down Expand Up @@ -227,7 +227,7 @@ fn check_cgroup_subsystem(
cgroup_name: &str,
subsystem: &str,
filename: &str,
expected: &dyn Any,
expected: &dyn ToString,
) -> Result<()> {
let cgroup_path = Path::new(CGROUP_ROOT)
.join(subsystem)
Expand All @@ -239,13 +239,7 @@ fn check_cgroup_subsystem(
let content = fs::read_to_string(&cgroup_path)
.with_context(|| format!("failed to read {cgroup_path:?}"))?;
let trimmed = content.trim();
if let Some(v) = expected.downcast_ref::<u64>() {
assert_eq!(&trimmed.parse::<u64>()?, v);
} else if let Some(v) = expected.downcast_ref::<i64>() {
assert_eq!(&trimmed.parse::<i64>()?, v);
} else if let Some(v) = expected.downcast_ref::<String>() {
assert_eq!(&trimmed, v);
}
assert_eq!(trimmed, expected.to_string());
Ok(())
}

Expand Down

0 comments on commit afbe94d

Please sign in to comment.