Re: [Libguestfs] [PATCH 2/2] rust: add some (but not yet all) tests
On Tue, Jun 20, 2023 at 09:31:37AM +, Tage Johansson wrote: > From: Tage Johansson > > --- > rust/Cargo.toml | 3 + > rust/tests/test_100_handle.rs | 25 > rust/tests/test_110_defaults.rs | 33 ++ > rust/tests/test_120_set_non_defaults.rs | 56 + > rust/tests/test_130_private_data.rs | 28 + > rust/tests/test_140_explicit_close.rs | 31 + > rust/tests/test_log/mod.rs | 84 + > 7 files changed, 260 insertions(+) > > diff --git a/rust/Cargo.toml b/rust/Cargo.toml > index f4fe8fb..d51c6cb 100644 > --- a/rust/Cargo.toml > +++ b/rust/Cargo.toml > @@ -46,3 +46,6 @@ log = { version = "0.4.19", optional = true } > > [features] > default = ["log"] > + > +[dev-dependencies] > +once_cell = "1.18.0" > diff --git a/rust/tests/test_100_handle.rs b/rust/tests/test_100_handle.rs > new file mode 100644 > index 000..d850466 > --- /dev/null > +++ b/rust/tests/test_100_handle.rs > @@ -0,0 +1,25 @@ > +// libnbd Rust test case > +// Copyright Red Hat > +// > +// This library is free software; you can redistribute it and/or > +// modify it under the terms of the GNU Lesser General Public > +// License as published by the Free Software Foundation; either > +// version 2 of the License, or (at your option) any later version. > +// > +// This library 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 > +// Lesser General Public License for more details. > +// > +// You should have received a copy of the GNU Lesser General Public > +// License along with this library; if not, write to the Free Software > +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + > +//! Just check that we can link with libnbd and create a handle. > + > +#![deny(warnings)] > + > +#[test] > +fn test_nbd_handle_new() { > +let _ = libnbd::NbdHandle::new().unwrap(); > +} > diff --git a/rust/tests/test_110_defaults.rs b/rust/tests/test_110_defaults.rs > new file mode 100644 > index 000..bcfab92 > --- /dev/null > +++ b/rust/tests/test_110_defaults.rs > @@ -0,0 +1,33 @@ > +// libnbd Rust test case > +// Copyright Red Hat > +// > +// This library is free software; you can redistribute it and/or > +// modify it under the terms of the GNU Lesser General Public > +// License as published by the Free Software Foundation; either > +// version 2 of the License, or (at your option) any later version. > +// > +// This library 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 > +// Lesser General Public License for more details. > +// > +// You should have received a copy of the GNU Lesser General Public > +// License along with this library; if not, write to the Free Software > +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + > +#![deny(warnings)] > + > +#[test] > +fn test_defaults() { > +let mut nbd = libnbd::NbdHandle::new().unwrap(); > + > +assert!(nbd.get_export_name().unwrap().to_str().unwrap().is_empty()); > +assert!(!nbd.get_full_info().unwrap()); > +assert_eq!(nbd.get_tls(), libnbd::Tls::Disable); > +assert!(nbd.get_request_structured_replies()); > +assert!(nbd.get_request_meta_context().unwrap()); > +assert!(nbd.get_request_block_size().unwrap()); > +assert!(nbd.get_pread_initialize()); > +assert!(nbd.get_handshake_flags().is_all()); > +assert!(!nbd.get_opt_mode()); > +} > diff --git a/rust/tests/test_120_set_non_defaults.rs > b/rust/tests/test_120_set_non_defaults.rs > new file mode 100644 > index 000..e46d088 > --- /dev/null > +++ b/rust/tests/test_120_set_non_defaults.rs > @@ -0,0 +1,56 @@ > +// libnbd Rust test case > +// Copyright Red Hat > +// > +// This library is free software; you can redistribute it and/or > +// modify it under the terms of the GNU Lesser General Public > +// License as published by the Free Software Foundation; either > +// version 2 of the License, or (at your option) any later version. > +// > +// This library 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 > +// Lesser General Public License for more details. > +// > +// You should have received a copy of the GNU Lesser General Public > +// License along with this library; if not, write to the Free Software > +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + > +#![deny(warnings)] > + > +use std::ffi::CString; > + > +#[test] > +fn test_set_non_defaults() { > +let mut nbd = libnbd::NbdHandle::new().unwrap(); > + > +let name = CString::new("name").un
[Libguestfs] [PATCH 2/2] rust: add some (but not yet all) tests
From: Tage Johansson --- rust/Cargo.toml | 3 + rust/tests/test_100_handle.rs | 25 rust/tests/test_110_defaults.rs | 33 ++ rust/tests/test_120_set_non_defaults.rs | 56 + rust/tests/test_130_private_data.rs | 28 + rust/tests/test_140_explicit_close.rs | 31 + rust/tests/test_log/mod.rs | 84 + 7 files changed, 260 insertions(+) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f4fe8fb..d51c6cb 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -46,3 +46,6 @@ log = { version = "0.4.19", optional = true } [features] default = ["log"] + +[dev-dependencies] +once_cell = "1.18.0" diff --git a/rust/tests/test_100_handle.rs b/rust/tests/test_100_handle.rs new file mode 100644 index 000..d850466 --- /dev/null +++ b/rust/tests/test_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Red Hat +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +//! Just check that we can link with libnbd and create a handle. + +#![deny(warnings)] + +#[test] +fn test_nbd_handle_new() { +let _ = libnbd::NbdHandle::new().unwrap(); +} diff --git a/rust/tests/test_110_defaults.rs b/rust/tests/test_110_defaults.rs new file mode 100644 index 000..bcfab92 --- /dev/null +++ b/rust/tests/test_110_defaults.rs @@ -0,0 +1,33 @@ +// libnbd Rust test case +// Copyright Red Hat +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#![deny(warnings)] + +#[test] +fn test_defaults() { +let mut nbd = libnbd::NbdHandle::new().unwrap(); + +assert!(nbd.get_export_name().unwrap().to_str().unwrap().is_empty()); +assert!(!nbd.get_full_info().unwrap()); +assert_eq!(nbd.get_tls(), libnbd::Tls::Disable); +assert!(nbd.get_request_structured_replies()); +assert!(nbd.get_request_meta_context().unwrap()); +assert!(nbd.get_request_block_size().unwrap()); +assert!(nbd.get_pread_initialize()); +assert!(nbd.get_handshake_flags().is_all()); +assert!(!nbd.get_opt_mode()); +} diff --git a/rust/tests/test_120_set_non_defaults.rs b/rust/tests/test_120_set_non_defaults.rs new file mode 100644 index 000..e46d088 --- /dev/null +++ b/rust/tests/test_120_set_non_defaults.rs @@ -0,0 +1,56 @@ +// libnbd Rust test case +// Copyright Red Hat +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#![deny(warnings)] + +use std::ffi::CString; + +#[test] +fn test_set_non_defaults() { +let mut nbd = libnbd::NbdHandle::new().unwrap(); + +let name = CString::new("name").unwrap(); +nbd.set_export_name(&name).unwrap(); +assert_eq!(nbd.get_export_name().unwrap(), name); + +nbd.set_full_info(true).unwrap(); +assert!(nbd.get_full_info().unwrap()); + +if nbd.supports_tls() { +nbd.set_tls(libnbd::Tls::Allow).unwrap(); +assert_eq!(nbd.get_tls(), libnbd::Tls::Allow