test_infra, tests: Introduce exec_host_command_output() function

This new function allows for better readability of the code by
factorizing a few of lines of code into a single one.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2021-06-04 10:09:10 +02:00
parent 8091c28dd5
commit 1e2aa769e5
2 changed files with 13 additions and 16 deletions

View File

@@ -964,20 +964,14 @@ mod tests {
guest.wait_vm_boot(None).unwrap();
if let Some(tap_name) = tap {
let tap_count = std::process::Command::new("bash")
.arg("-c")
.arg(format!("ip link | grep -c {}", tap_name))
.output()
.expect("Expected checking of tap count to succeed");
let tap_count =
exec_host_command_output(&format!("ip link | grep -c {}", tap_name));
assert_eq!(String::from_utf8_lossy(&tap_count.stdout).trim(), "1");
}
if let Some(host_mac) = tap {
let mac_count = std::process::Command::new("bash")
.arg("-c")
.arg(format!("ip link | grep -c {}", host_mac))
.output()
.expect("Expected checking of host mac to succeed");
let mac_count =
exec_host_command_output(&format!("ip link | grep -c {}", host_mac));
assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
}
@@ -2740,11 +2734,7 @@ mod tests {
let r = std::panic::catch_unwind(|| {
guest.wait_vm_boot(None).unwrap();
let tap_count = std::process::Command::new("bash")
.arg("-c")
.arg("ip link | grep -c mytap1")
.output()
.expect("Expected checking of tap count to succeed");
let tap_count = exec_host_command_output("ip link | grep -c mytap1");
assert_eq!(String::from_utf8_lossy(&tap_count.stdout).trim(), "1");
// 3 network interfaces + default localhost ==> 4 interfaces