Skip to content

Commit

Permalink
test: use is_ok/is_err replace match for Result return type
Browse files Browse the repository at this point in the history
In test cases, we can use is_ok or is_err against to Result type,
instead of using a match.

Signed-off-by: bin liu <bin@hyper.sh>
  • Loading branch information
liubin committed Feb 24, 2022
1 parent aff5dea commit 8059e51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! endpoint {
}

lazy_static! {
/// HTTP_ROUTES contain all the cloud-hypervisor HTTP routes.
/// HTTP_ROUTES contain all the nydusd HTTP routes.
pub static ref HTTP_ROUTES: HttpRoutes = {
let mut r = HttpRoutes {
routes: HashMap::new(),
Expand Down
46 changes: 20 additions & 26 deletions src/bin/nydusd/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,21 +634,18 @@ mod tests {
#[test]
fn it_should_add_new_backend() {
let mut col: FsBackendCollection = Default::default();
if col
.add(
"test",
&FsBackendMountCmd {
fs_type: FsBackendType::Rafs,
config: "{\"config\": \"test\"}".to_string(),
mountpoint: "testmonutount".to_string(),
source: "testsource".to_string(),
prefetch_files: Some(vec!["testfile".to_string()]),
},
)
.is_err()
{
panic!("failed to add backend collection")
}
let r = col.add(
"test",
&FsBackendMountCmd {
fs_type: FsBackendType::Rafs,
config: "{\"config\": \"test\"}".to_string(),
mountpoint: "testmonutount".to_string(),
source: "testsource".to_string(),
prefetch_files: Some(vec!["testfile".to_string()]),
},
);
assert!(r.is_ok(), "failed to add backend collection");

assert_eq!(col.0.len(), 1);

col.del("test");
Expand All @@ -657,17 +654,14 @@ mod tests {

#[test]
fn it_should_verify_prefetch_files() {
match input_prefetch_files_verify(&Some(vec!["/etc/passwd".to_string()])) {
Err(_) => panic!("failed to verify prefetch files"),
Ok(res) => match res {
Some(v) => assert_eq!(1, v.len()),
None => panic!("failed to get verified prefetch files"),
},
}

if input_prefetch_files_verify(&Some(vec!["etc/passwd".to_string()])).is_ok() {
panic!("should not pass verify");
}
let files = input_prefetch_files_verify(&Some(vec!["/etc/passwd".to_string()]));
assert!(files.is_ok(), "failed to verify prefetch files");
assert_eq!(1, files.unwrap().unwrap().len());

assert!(
input_prefetch_files_verify(&Some(vec!["etc/passwd".to_string()])).is_err(),
"should not pass verify"
);
}

#[test]
Expand Down
10 changes: 7 additions & 3 deletions src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ fn main() -> Result<()> {
d
})
.map_err(|e| {
error!("Failed in starting daemon, {}", e);
error!("Failed in starting daemon: {}", e);
e
})?
};
Expand Down Expand Up @@ -481,8 +481,12 @@ fn main() -> Result<()> {
}
}

daemon.stop().unwrap_or_else(|e| error!("{}", e));
daemon.wait().unwrap_or_else(|e| error!("{}", e));
daemon
.stop()
.unwrap_or_else(|e| error!("failed to stop daemon: {}", e));
daemon
.wait()
.unwrap_or_else(|e| error!("failed to wait daemon: {}", e));
info!("nydusd quits");

Ok(())
Expand Down

0 comments on commit 8059e51

Please sign in to comment.