[Libguestfs] [PATCH 10/12] Rust bindings: Add additional 4 bindings tests

Hiroyuki Katsura hiroyuki.katsura.0513 at gmail.com
Tue Jul 2 13:14:28 UTC 2019


---
 rust/tests/050_handle_properties.rs | 61 +++++++++++++++++++++++++++
 rust/tests/070_opt_args.rs          | 36 ++++++++++++++++
 rust/tests/080_version.rs           | 29 +++++++++++++
 rust/tests/100_launch.rs            | 65 +++++++++++++++++++++++++++++
 4 files changed, 191 insertions(+)
 create mode 100644 rust/tests/050_handle_properties.rs
 create mode 100644 rust/tests/070_opt_args.rs
 create mode 100644 rust/tests/080_version.rs
 create mode 100644 rust/tests/100_launch.rs

diff --git a/rust/tests/050_handle_properties.rs b/rust/tests/050_handle_properties.rs
new file mode 100644
index 000000000..3c7b449f9
--- /dev/null
+++ b/rust/tests/050_handle_properties.rs
@@ -0,0 +1,61 @@
+/* libguestfs Python bindings
+ Copyright (C) 2009-2019 Red Hat Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+extern crate guestfs;
+
+use std::default::Default;
+
+#[test]
+fn verbose() {
+    let g = guestfs::Handle::create().expect("create");
+    g.set_verbose(true).expect("set_verbose");
+    assert_eq!(g.get_verbose().expect("get_verbose"), true);
+    g.set_verbose(false).expect("set_verbose");
+    assert_eq!(g.get_verbose().expect("get_verbose"), false);
+}
+
+#[test]
+fn trace() {
+    let g = guestfs::Handle::create().expect("create");
+    g.set_trace(true).expect("set_trace");
+    assert_eq!(g.get_trace().expect("get_trace"), true);
+    g.set_trace(false).expect("set_trace");
+    assert_eq!(g.get_trace().expect("get_trace"), false);
+}
+
+#[test]
+fn autosync() {
+    let g = guestfs::Handle::create().expect("create");
+    g.set_autosync(true).expect("set_autosync");
+    assert_eq!(g.get_autosync().expect("get_autosync"), true);
+    g.set_autosync(false).expect("set_autosync");
+    assert_eq!(g.get_autosync().expect("get_autosync"), false);
+}
+
+#[test]
+fn path() {
+    let g = guestfs::Handle::create().expect("create");
+    g.set_path(Some(".")).expect("set_path");
+    assert_eq!(g.get_path().expect("get_path"), ".");
+}
+
+#[test]
+fn add_drive() {
+    let g = guestfs::Handle::create().expect("create");
+    g.add_drive("/dev/null", Default::default()).expect("add_drive");
+}
diff --git a/rust/tests/070_opt_args.rs b/rust/tests/070_opt_args.rs
new file mode 100644
index 000000000..241c95b35
--- /dev/null
+++ b/rust/tests/070_opt_args.rs
@@ -0,0 +1,36 @@
+/* libguestfs Python bindings
+ Copyright (C) 2009-2019 Red Hat Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+extern crate guestfs;
+
+use std::default::Default;
+
+#[test]
+fn no_optargs() {
+    let g = guestfs::Handle::create().expect("create");
+    g.add_drive("/dev/null", Default::default())
+        .expect("add_drive");
+}
+
+#[test]
+fn one_optarg() {
+    let g = guestfs::Handle::create().expect("create");
+    g.add_drive("/dev/null",
+        guestfs::OptArgsAddDrive::default().readonly(true))
+        .expect("add_drive");
+}
diff --git a/rust/tests/080_version.rs b/rust/tests/080_version.rs
new file mode 100644
index 000000000..ab5314edc
--- /dev/null
+++ b/rust/tests/080_version.rs
@@ -0,0 +1,29 @@
+/* libguestfs Python bindings
+ Copyright (C) 2009-2019 Red Hat Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+extern crate guestfs;
+
+use std::default::Default;
+
+#[test]
+fn version() {
+    let g = guestfs::Handle::create().expect("create");
+    let v = g.version().expect("version");
+    assert_eq!(v.major, 1)
+}
+
diff --git a/rust/tests/100_launch.rs b/rust/tests/100_launch.rs
new file mode 100644
index 000000000..1c1d8146a
--- /dev/null
+++ b/rust/tests/100_launch.rs
@@ -0,0 +1,65 @@
+/* libguestfs Rust bindings
+Copyright (C) 2009-2019 Red Hat Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+extern crate guestfs;
+
+use std::default::Default;
+
+#[test]
+fn launch() {
+    let g = guestfs::Handle::create().expect("create");
+    g.add_drive_scratch(500 * 1024 * 1024, Default::default())
+        .expect("add_drive_scratch");
+    g.launch().expect("launch");
+    g.pvcreate("/dev/sda").expect("pvcreate");
+    g.vgcreate("VG", &["/dev/sda"]).expect("vgcreate");
+    g.lvcreate("LV1", "VG", 200).expect("lvcreate");
+    g.lvcreate("LV2", "VG", 200).expect("lvcreate");
+
+    let lvs = g.lvs().expect("lvs");
+    assert_eq!(
+        lvs,
+        vec!["/dev/VG/LV1".to_string(), "/dev/VG/LV2".to_string()]
+    );
+
+    g.mkfs("ext2", "/dev/VG/LV1", Default::default())
+        .expect("mkfs");
+    g.mount("/dev/VG/LV1", "/").expect("mount");
+    g.mkdir("/p").expect("mkdir");
+    g.touch("/q").expect("touch");
+
+    let mut dirs = g.readdir("/").expect("readdir");
+
+    dirs.sort_by(|a, b| a.name.cmp(&b.name));
+
+    let mut v = Vec::new();
+    for x in &dirs {
+        v.push((x.name.as_str(), x.ftyp as u8));
+    }
+    assert_eq!(
+        v,
+        vec![
+            (".", b'd'),
+            ("..", b'd'),
+            ("lost+found", b'd'),
+            ("p", b'd'),
+            ("q", b'r')
+        ]
+    );
+    g.shutdown().expect("shutdown");
+}
-- 
2.20.1 (Apple Git-117)




More information about the Libguestfs mailing list