mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Eliminate use of assert!((...).is_ok())
Asserting on .is_ok()/.is_err() leads to hard to debug failures (as if the test fails, it will only say "assertion failed: false". We replace these with `.unwrap()`, which also prints the exact error variant that was unexpectedly encountered (we can to this these days thanks to efforts to implement Display and Debug for our error types). If the assert!((...).is_ok()) was followed by an .unwrap() anyway, we just drop the assert. Inspired by and quoted from @roypat. Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
@@ -362,13 +362,13 @@ fn _test_api_pause_resume(target_api: TargetApi, guest: Guest) {
|
||||
thread::sleep(std::time::Duration::new(2, 0));
|
||||
|
||||
// SSH into the VM should fail
|
||||
assert!(ssh_command_ip(
|
||||
ssh_command_ip(
|
||||
"grep -c processor /proc/cpuinfo",
|
||||
&guest.network.guest_ip,
|
||||
2,
|
||||
5
|
||||
5,
|
||||
)
|
||||
.is_err());
|
||||
.unwrap_err();
|
||||
|
||||
// Resume the VM
|
||||
assert!(target_api.remote_command("resume", None));
|
||||
@@ -6580,7 +6580,7 @@ mod common_parallel {
|
||||
thread::sleep(std::time::Duration::new(5, 0));
|
||||
|
||||
// Check the connection fails this time
|
||||
assert!(guest2.ssh_command("nc -vz 172.100.0.1 12345").is_err());
|
||||
guest2.ssh_command("nc -vz 172.100.0.1 12345").unwrap_err();
|
||||
|
||||
// Add the OVS port back
|
||||
assert!(exec_host_command_status("ovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/dpdkvhostclient1").success());
|
||||
|
||||
Reference in New Issue
Block a user