[libvirt] [PATCH Rust v2 2/6] make lookup_by_id() test more robust

Sahid Orentino Ferdjaoui sahid.ferdjaoui at canonical.com
Tue Jul 9 07:42:03 UTC 2019


Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui at canonical.com>
---
 tests/domain.rs | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tests/domain.rs b/tests/domain.rs
index 5a64a75..dcf7dd9 100644
--- a/tests/domain.rs
+++ b/tests/domain.rs
@@ -91,14 +91,13 @@ fn test_get_vcpus_flags() {
 #[test]
 fn test_lookup_domain_by_id() {
     let c = common::conn();
-    let v = c.list_domains().unwrap_or(vec![]);
-    assert!(0 < v.len(), "At least one domain should exist");
-    for domid in v {
-        match Domain::lookup_by_id(&c, domid) {
-            Ok(mut dom) => dom.free().unwrap_or(()),
-            Err(e) => panic!("failed with code {}, message: {}", e.code, e.message),
-        }
+    let d = common::build_test_domain(&c, "by_id", true);
+    let id = d.get_id().unwrap_or(0);
+    match Domain::lookup_by_id(&c, id) {
+        Ok(mut r) => r.free().unwrap_or(()),
+        Err(e) => panic!("failed with code {}, message: {}", e.code, e.message),
     }
+    common::clean(d);
     common::close(c);
 }
 
-- 
2.17.1




More information about the libvir-list mailing list