Skip to content

Commit

Permalink
Merge pull request #187 from Apokleos/enhance-ns-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k authored Jul 11, 2024
2 parents 80e8e8d + 83beeb4 commit 1b54239
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,13 @@ impl TryFrom<&str> for LinuxNamespaceType {

fn try_from(namespace: &str) -> Result<Self, Self::Error> {
match namespace {
"mnt" => Ok(LinuxNamespaceType::Mount),
"mnt" | "mount" => Ok(LinuxNamespaceType::Mount),
"cgroup" => Ok(LinuxNamespaceType::Cgroup),
"uts" => Ok(LinuxNamespaceType::Uts),
"ipc" => Ok(LinuxNamespaceType::Ipc),
"user" => Ok(LinuxNamespaceType::User),
"pid" => Ok(LinuxNamespaceType::Pid),
"net" => Ok(LinuxNamespaceType::Network),
"net" | "network" => Ok(LinuxNamespaceType::Network),
"time" => Ok(LinuxNamespaceType::Time),
_ => Err(oci_error(format!(
"unknown namespace {namespace}, could not convert"
Expand Down Expand Up @@ -1525,6 +1525,10 @@ mod tests {
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Network);

let nstype_str = "network";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Network);

let nstype_str = "ipc";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Ipc);
Expand All @@ -1533,7 +1537,11 @@ mod tests {
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Cgroup);

let invalid_nstype_str = "mount";
let nstype_str = "mount";
let nstype_enum = LinuxNamespaceType::try_from(nstype_str).unwrap();
assert_eq!(nstype_enum, LinuxNamespaceType::Mount);

let invalid_nstype_str = "xxx";
let unknown_nstype = LinuxNamespaceType::try_from(invalid_nstype_str);
assert!(unknown_nstype.is_err());
}
Expand Down

0 comments on commit 1b54239

Please sign in to comment.