[libvirt] [PATCH rust 2/5] make lookup_by_id() test more robust

Sahid Orentino Ferdjaoui sahid.ferdjaoui at canonical.com
Thu Jul 4 10:15:26 UTC 2019


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

diff --git a/tests/domain.rs b/tests/domain.rs
index 5a64a75..a70139e 100644
--- a/tests/domain.rs
+++ b/tests/domain.rs
@@ -89,26 +89,25 @@ fn test_get_vcpus_flags() {
 }
 
 #[test]
-fn test_lookup_domain_by_id() {
+fn test_lookup_domain_by_name() {
     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),
-        }
+    match Domain::lookup_by_name(&c, "test") {
+        Ok(mut r) => r.free().unwrap_or(()),
+        Err(e) => panic!("failed with code {}, message: {}", e.code, e.message),
     }
     common::close(c);
 }
 
 #[test]
-fn test_lookup_domain_by_name() {
+fn test_lookup_domain_by_id() {
     let c = common::conn();
-    match Domain::lookup_by_name(&c, "test") {
+    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.20.1




More information about the libvir-list mailing list