diff --git a/src/cli/global_args.rs b/src/cli/global_args.rs index c4d1fa4..806e2f2 100644 --- a/src/cli/global_args.rs +++ b/src/cli/global_args.rs @@ -249,13 +249,13 @@ enum SshMode { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; #[test] - fn default_args_serialize_empty() { - let global_args = crate::serde::args::to_string(GlobalArgs::default()).unwrap(); + fn default_args_serialize_empty() -> Result<(), crate::serde::args::Error> { + let global_args = crate::serde::args::to_string(GlobalArgs::default())?; assert!(global_args.is_empty()); + Ok(()) } } diff --git a/src/quadlet/container/device.rs b/src/quadlet/container/device.rs index e12ba22..93c93cc 100644 --- a/src/quadlet/container/device.rs +++ b/src/quadlet/container/device.rs @@ -189,14 +189,13 @@ impl From for Device { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; #[test] - fn host() { + fn host() -> Result<(), ParseDeviceError> { let string = "/host"; - let device = Device::from_str(string).unwrap(); + let device = Device::from_str(string)?; assert_eq!( device, @@ -211,13 +210,15 @@ mod tests { assert_eq!(device.to_string(), string); - assert_eq!(device, "/host::".parse().unwrap()); + assert_eq!(device, "/host::".parse()?); + + Ok(()) } #[test] - fn host_container() { + fn host_container() -> Result<(), ParseDeviceError> { let string = "/host:/container"; - let device = Device::from_str(string).unwrap(); + let device = Device::from_str(string)?; assert_eq!( device, @@ -232,13 +233,15 @@ mod tests { assert_eq!(device.to_string(), string); - assert_eq!(device, "/host:/container:".parse().unwrap()); + assert_eq!(device, "/host:/container:".parse()?); + + Ok(()) } #[test] - fn host_permissions() { + fn host_permissions() -> Result<(), ParseDeviceError> { let string = "/host:rwm"; - let device = Device::from_str(string).unwrap(); + let device = Device::from_str(string)?; assert_eq!( device, @@ -253,14 +256,16 @@ mod tests { assert_eq!(device.to_string(), string); - assert_eq!(device, "/host::rwm".parse().unwrap()); - assert_eq!(device, "/host:r:wm".parse().unwrap()); + assert_eq!(device, "/host::rwm".parse()?); + assert_eq!(device, "/host:r:wm".parse()?); + + Ok(()) } #[test] - fn host_container_permissions() { + fn host_container_permissions() -> Result<(), ParseDeviceError> { let string = "/host:/container:rwm"; - let device = Device::from_str(string).unwrap(); + let device = Device::from_str(string)?; assert_eq!( device, @@ -274,25 +279,24 @@ mod tests { ); assert_eq!(device.to_string(), string); + + Ok(()) } #[test] fn empty_host_err() { assert_eq!( - Device::from_str(":/container").unwrap_err(), - ParseDeviceError::EmptyHostPath, - ); - assert_eq!( - Device::from_str("").unwrap_err(), - ParseDeviceError::EmptyHostPath, + Device::from_str(":/container"), + Err(ParseDeviceError::EmptyHostPath), ); + assert_eq!(Device::from_str(""), Err(ParseDeviceError::EmptyHostPath)); } #[test] fn unknown_permission_err() { assert_eq!( - Device::from_str("/host:a").unwrap_err(), - ParseDeviceError::UnknownPermission('a'), + Device::from_str("/host:a"), + Err(ParseDeviceError::UnknownPermission('a')), ); } } diff --git a/src/quadlet/container/mount.rs b/src/quadlet/container/mount.rs index d21b9be..82511e6 100644 --- a/src/quadlet/container/mount.rs +++ b/src/quadlet/container/mount.rs @@ -443,14 +443,13 @@ impl Volume { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; #[test] - fn bind() { + fn bind() -> Result<(), ParseMountError> { let string = "type=bind,source=/src,destination=/dst"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Bind(Bind { @@ -462,7 +461,7 @@ mod tests { let string = "type=bind,source=/src,destination=/dst,readonly=true,bind-propagation=shared,\ bind-nonrecursive=true,relabel=shared,idmap,chown=true,no-dereference=true"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Bind(Bind { @@ -478,17 +477,19 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn devpts() { + fn devpts() -> Result<(), ParseMountError> { let string = "type=devpts,destination=/dst"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!(mount, Mount::DevPts(DevPts::new("/dst".into()))); assert_eq!(mount.to_string(), string); let string = "type=devpts,destination=/dst,uid=100,gid=100,mode=755,max=10"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::DevPts(DevPts { @@ -500,12 +501,14 @@ mod tests { }) ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn glob() { + fn glob() -> Result<(), ParseMountError> { let string = "type=glob,source=/usr/lib/libfoo*,destination=/usr/lib,readonly=true"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Glob(Bind { @@ -515,13 +518,15 @@ mod tests { }) ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn image() { + fn image() -> Result<(), ParseMountError> { let string = "type=image,source=fedora,destination=/fedora-image,readwrite=true,subpath=path"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Image(Image { @@ -532,13 +537,15 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn ramfs() { + fn ramfs() -> Result<(), ParseMountError> { let string = "type=ramfs,destination=/dst,readonly=true,\ tmpfs-size=256m,tmpfs-mode=755,notmpcopyup,chown=true"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Ramfs(Tmpfs { @@ -551,13 +558,15 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn tmpfs() { + fn tmpfs() -> Result<(), ParseMountError> { let string = "type=tmpfs,destination=/dst,readonly=true,\ tmpfs-size=256m,tmpfs-mode=755,notmpcopyup,chown=true"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Tmpfs(Tmpfs { @@ -570,18 +579,20 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn volume() { + fn volume() -> Result<(), ParseMountError> { let string = "type=volume,destination=/dst"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!(mount, Mount::Volume(Volume::new("/dst".into())),); assert_eq!(mount.to_string(), string); let string = "type=volume,source=volume,destination=/dst,readonly=true,chown=true,\ idmap=uids=@0-1-2,subpath=/subpath"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, Mount::Volume(Volume { @@ -602,5 +613,7 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } } diff --git a/src/quadlet/container/mount/idmap.rs b/src/quadlet/container/mount/idmap.rs index ddf6111..a44116c 100644 --- a/src/quadlet/container/mount/idmap.rs +++ b/src/quadlet/container/mount/idmap.rs @@ -265,16 +265,15 @@ impl Display for Mapping { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use serde::de::value::UnitDeserializer; use super::*; #[test] - fn uids() { + fn uids() -> Result<(), ParseIdmapError> { let string = "uids=0-1-2#@3-4-5"; - let idmap: Idmap = string.parse().unwrap(); + let idmap: Idmap = string.parse()?; assert_eq!( idmap, @@ -297,12 +296,14 @@ mod tests { }, ); assert_eq!(idmap.to_string(), string); + + Ok(()) } #[test] - fn gids() { + fn gids() -> Result<(), ParseIdmapError> { let string = "gids=0-1-2#@3-4-5"; - let idmap: Idmap = string.parse().unwrap(); + let idmap: Idmap = string.parse()?; assert_eq!( idmap, @@ -325,12 +326,14 @@ mod tests { }, ); assert_eq!(idmap.to_string(), string); + + Ok(()) } #[test] - fn uids_and_gids() { + fn uids_and_gids() -> Result<(), ParseIdmapError> { let string = "uids=0-1-2;gids=3-4-5"; - let idmap: Idmap = string.parse().unwrap(); + let idmap: Idmap = string.parse()?; assert_eq!( idmap, @@ -350,18 +353,21 @@ mod tests { }, ); assert_eq!(idmap.to_string(), string); + + Ok(()) } #[test] - fn deserialize_unit() { - let idmap = Idmap::deserialize(UnitDeserializer::::new()).unwrap(); + fn deserialize_unit() -> Result<(), de::value::Error> { + let idmap = Idmap::deserialize(UnitDeserializer::new())?; assert_eq!(idmap, Idmap::default()); + Ok(()) } #[test] - fn mapping_round_trip() { + fn mapping_round_trip() -> Result<(), ParseMappingError> { let string = "@0-1-2"; - let mapping: Mapping = string.parse().unwrap(); + let mapping: Mapping = string.parse()?; assert_eq!( mapping, @@ -373,5 +379,7 @@ mod tests { }, ); assert_eq!(mapping.to_string(), string); + + Ok(()) } } diff --git a/src/quadlet/container/mount/mode.rs b/src/quadlet/container/mount/mode.rs index 16640da..fc64d33 100644 --- a/src/quadlet/container/mount/mode.rs +++ b/src/quadlet/container/mount/mode.rs @@ -30,7 +30,6 @@ pub fn skip_default(mode: &Mode) -> bool { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use std::fmt::{self, Display, Formatter}; @@ -58,8 +57,9 @@ mod tests { } #[test] - fn deserialize_string() { - let mode = deserialize(BorrowedStrDeserializer::::new("755")).unwrap(); + fn deserialize_string() -> Result<(), Error> { + let mode = deserialize(BorrowedStrDeserializer::new("755"))?; assert_eq!(mode, Mode::from(0o755)); + Ok(()) } } diff --git a/src/quadlet/container/mount/tmpfs.rs b/src/quadlet/container/mount/tmpfs.rs index 0d1e740..ec9f235 100644 --- a/src/quadlet/container/mount/tmpfs.rs +++ b/src/quadlet/container/mount/tmpfs.rs @@ -391,9 +391,11 @@ impl<'de> Deserialize<'de> for Size { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { - use super::{super::Mount, *}; + use super::{ + super::{Mount, ParseMountError}, + *, + }; #[test] fn mode_default() { @@ -401,23 +403,25 @@ mod tests { } #[test] - fn defaults() { + fn defaults() -> Result<(), ParseMountError> { let string = "type=tmpfs,destination=/test"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!(mount, Mount::Tmpfs(Tmpfs::new("/test".into()))); assert_eq!(mount.to_string(), string); + + Ok(()) } #[test] - fn tmpcopyup() { - let mount: Mount = "type=tmpfs,destination=/test,tmpcopyup".parse().unwrap(); + fn tmpcopyup() -> Result<(), ParseMountError> { + let mount: Mount = "type=tmpfs,destination=/test,tmpcopyup".parse()?; // tmpcopyup default is true assert_eq!(mount, Mount::Tmpfs(Tmpfs::new("/test".into()))); let string = "type=tmpfs,destination=/test,notmpcopyup"; - let mount: Mount = string.parse().unwrap(); + let mount: Mount = string.parse()?; assert_eq!( mount, @@ -427,5 +431,7 @@ mod tests { }), ); assert_eq!(mount.to_string(), string); + + Ok(()) } } diff --git a/src/quadlet/container/rootfs.rs b/src/quadlet/container/rootfs.rs index 7278048..93ee0d6 100644 --- a/src/quadlet/container/rootfs.rs +++ b/src/quadlet/container/rootfs.rs @@ -136,16 +136,15 @@ pub enum ParseRootfsError { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::super::mount::idmap::Mapping; use super::*; #[test] - fn path() { + fn path() -> Result<(), ParseRootfsError> { let string = "/test"; - let rootfs: Rootfs = string.parse().unwrap(); + let rootfs: Rootfs = string.parse()?; assert_eq!( rootfs, @@ -156,12 +155,14 @@ mod tests { }, ); assert_eq!(rootfs.to_string(), string); + + Ok(()) } #[test] - fn overlay() { + fn overlay() -> Result<(), ParseRootfsError> { let string = "/test:O"; - let rootfs: Rootfs = string.parse().unwrap(); + let rootfs: Rootfs = string.parse()?; assert_eq!( rootfs, @@ -172,12 +173,14 @@ mod tests { }, ); assert_eq!(rootfs.to_string(), string); + + Ok(()) } #[test] - fn idmap() { + fn idmap() -> Result<(), ParseRootfsError> { let string = "/test:idmap=uids=0-1-2"; - let rootfs: Rootfs = string.parse().unwrap(); + let rootfs: Rootfs = string.parse()?; assert_eq!( rootfs, @@ -196,12 +199,14 @@ mod tests { }, ); assert_eq!(rootfs.to_string(), string); + + Ok(()) } #[test] - fn overlay_and_idmap() { + fn overlay_and_idmap() -> Result<(), ParseRootfsError> { let string = "/test:O,idmap"; - let rootfs: Rootfs = string.parse().unwrap(); + let rootfs: Rootfs = string.parse()?; assert_eq!( rootfs, @@ -212,5 +217,7 @@ mod tests { }, ); assert_eq!(rootfs.to_string(), string); + + Ok(()) } } diff --git a/src/quadlet/container/volume.rs b/src/quadlet/container/volume.rs index c80b863..a84b213 100644 --- a/src/quadlet/container/volume.rs +++ b/src/quadlet/container/volume.rs @@ -666,22 +666,22 @@ impl Display for Overlay { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; #[test] - fn container_only() { + fn container_only() -> Result<(), ParseVolumeError> { let string = "/container/path"; - let volume: Volume = string.parse().unwrap(); + let volume: Volume = string.parse()?; assert_eq!(volume, Volume::new("/container/path".into())); assert_eq!(volume.to_string(), string); + Ok(()) } #[test] - fn source_and_container() { + fn source_and_container() -> Result<(), ParseVolumeError> { let string = "/host/path:/container/path"; - let volume: Volume = string.parse().unwrap(); + let volume: Volume = string.parse()?; assert_eq!( volume, Volume { @@ -691,13 +691,14 @@ mod tests { }, ); assert_eq!(volume.to_string(), string); + Ok(()) } #[test] - fn all_options() { + fn all_options() -> Result<(), ParseVolumeError> { let string = "/host/path:/container/path:ro,Z,O,upperdir=/upper/dir,workdir=/work/dir,U,\ nocopy,dev,noexec,suid,rbind,shared,idmap"; - let volume: Volume = string.parse().unwrap(); + let volume: Volume = string.parse()?; let options = Options { read_only: true, selinux_relabel: Some(SELinuxRelabel::Private), @@ -723,5 +724,6 @@ mod tests { } ); assert_eq!(volume.to_string(), string); + Ok(()) } } diff --git a/src/serde/args.rs b/src/serde/args.rs index dbe02c7..444ddbe 100644 --- a/src/serde/args.rs +++ b/src/serde/args.rs @@ -25,7 +25,8 @@ use crate::escape::arg_quote; /// str: "Hello world!", /// vec: vec![1, 2], /// }; -/// assert_eq!(to_string(example).unwrap(), "--str \"Hello world!\" --vec 1 --vec 2"); +/// assert_eq!(to_string(example)?, "--str \"Hello world!\" --vec 1 --vec 2"); +/// # Ok::<(), Error>(()) /// ``` pub fn to_string(value: T) -> Result { let mut serializer = Serializer::default(); @@ -488,12 +489,11 @@ impl ser::SerializeTupleVariant for &mut ValueSerializer<'_> { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; #[test] - fn basic_struct() { + fn basic_struct() -> Result<(), Error> { #[derive(Serialize)] #[serde(rename_all = "kebab-case")] struct Test { @@ -505,11 +505,13 @@ mod tests { option_one: "one", two: 2, }; - assert_eq!(to_string(sut).unwrap(), "--option-one one --two 2"); + assert_eq!(to_string(sut)?, "--option-one one --two 2"); + + Ok(()) } #[test] - fn struct_with_sequence() { + fn struct_with_sequence() -> Result<(), Error> { #[derive(Serialize)] struct Test { tuple: (u16, u32, u64), @@ -523,15 +525,17 @@ mod tests { vec: vec!["one", "two", "three"], }; assert_eq!( - to_string(sut).unwrap(), + to_string(sut)?, "--tuple 1 --tuple 2 --tuple 3 \ --array a --array b --array c \ --vec one --vec two --vec three" ); + + Ok(()) } #[test] - fn escape_values() { + fn escape_values() -> Result<(), Error> { #[derive(Serialize)] struct Test { test: &'static str, @@ -540,11 +544,13 @@ mod tests { let sut = Test { test: "Hello, world!", }; - assert_eq!(to_string(sut).unwrap(), "--test 'Hello, world!'"); + assert_eq!(to_string(sut)?, "--test 'Hello, world!'"); + + Ok(()) } #[test] - fn bool() { + fn bool() -> Result<(), Error> { #[derive(Serialize)] struct Test { yes: bool, @@ -555,11 +561,13 @@ mod tests { yes: true, no: false, }; - assert_eq!(to_string(sut).unwrap(), "--yes --no=false"); + assert_eq!(to_string(sut)?, "--yes --no=false"); + + Ok(()) } #[test] - fn enum_value() { + fn enum_value() -> Result<(), Error> { #[derive(Serialize)] #[serde(rename_all = "kebab-case")] enum Enum { @@ -578,7 +586,9 @@ mod tests { two: Enum::Two, }; - assert_eq!(to_string(sut).unwrap(), "--one one --two two"); + assert_eq!(to_string(sut)?, "--one one --two two"); + + Ok(()) } #[test] @@ -596,7 +606,7 @@ mod tests { let sut = Test { nested: Nested { nested: "nested" }, }; - assert_eq!(to_string(sut).unwrap_err(), Error::Nested); + assert_eq!(to_string(sut), Err(Error::Nested)); } #[test] @@ -614,9 +624,9 @@ mod tests { } let sut = Test1 { empty: () }; - assert_eq!(to_string(sut).unwrap_err(), Error::InvalidFlag); + assert_eq!(to_string(sut), Err(Error::InvalidFlag)); let sut = Test2 { spaces: () }; - assert_eq!(to_string(sut).unwrap_err(), Error::InvalidFlag); + assert_eq!(to_string(sut), Err(Error::InvalidFlag)); } } diff --git a/src/serde/mount_options.rs b/src/serde/mount_options.rs index dc187d5..ce353fa 100644 --- a/src/serde/mount_options.rs +++ b/src/serde/mount_options.rs @@ -34,9 +34,10 @@ mod ser; /// option: false, /// }; /// assert_eq!( -/// to_string(example).unwrap(), +/// to_string(example)?, /// "hello=world,option=false", /// ); +/// # Ok::<(), Error>(()) /// ``` pub fn to_string(value: T) -> Result { let mut serializer = Serializer::default(); @@ -102,7 +103,6 @@ impl serde::de::Error for Error { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use super::*; @@ -153,34 +153,38 @@ mod tests { } #[test] - fn serialize() { - assert_eq!(to_string(Test::new()).unwrap(), Test::DEFAULT); + fn serialize() -> Result<(), Error> { + assert_eq!(to_string(Test::new())?, Test::DEFAULT); + Ok(()) } #[test] - fn deserialize() { - let test: Test = from_str(Test::DEFAULT).unwrap(); + fn deserialize() -> Result<(), Error> { + let test: Test = from_str(Test::DEFAULT)?; assert_eq!(test, Test::new()); + Ok(()) } #[test] - fn deserialize_bool() { + fn deserialize_bool() -> Result<(), Error> { #[derive(Deserialize, Debug, PartialEq, Eq)] struct Test { #[serde(default)] bool: bool, } - let test: Test = from_str("bool=true").unwrap(); + let test: Test = from_str("bool=true")?; assert_eq!(test, Test { bool: true }); - let test: Test = from_str("bool=false").unwrap(); + let test: Test = from_str("bool=false")?; assert_eq!(test, Test { bool: false }); - let test: Test = from_str("bool").unwrap(); + let test: Test = from_str("bool")?; assert_eq!(test, Test { bool: true }); - let test: Test = from_str("").unwrap(); + let test: Test = from_str("")?; assert_eq!(test, Test { bool: false }); + + Ok(()) } }