Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli/global_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
46 changes: 25 additions & 21 deletions src/quadlet/container/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ impl From<service::Device> 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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')),
);
}
}
49 changes: 31 additions & 18 deletions src/quadlet/container/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -602,5 +613,7 @@ mod tests {
}),
);
assert_eq!(mount.to_string(), string);

Ok(())
}
}
30 changes: 19 additions & 11 deletions src/quadlet/container/mount/idmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -350,18 +353,21 @@ mod tests {
},
);
assert_eq!(idmap.to_string(), string);

Ok(())
}

#[test]
fn deserialize_unit() {
let idmap = Idmap::deserialize(UnitDeserializer::<de::value::Error>::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,
Expand All @@ -373,5 +379,7 @@ mod tests {
},
);
assert_eq!(mapping.to_string(), string);

Ok(())
}
}
6 changes: 3 additions & 3 deletions src/quadlet/container/mount/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -58,8 +57,9 @@ mod tests {
}

#[test]
fn deserialize_string() {
let mode = deserialize(BorrowedStrDeserializer::<Error>::new("755")).unwrap();
fn deserialize_string() -> Result<(), Error> {
let mode = deserialize(BorrowedStrDeserializer::new("755"))?;
assert_eq!(mode, Mode::from(0o755));
Ok(())
}
}
Loading