diff --git a/systeroid-core/src/sysctl/section.rs b/systeroid-core/src/sysctl/section.rs index e6e5e7a..d1f49f7 100644 --- a/systeroid-core/src/sysctl/section.rs +++ b/systeroid-core/src/sysctl/section.rs @@ -37,8 +37,10 @@ impl From for Section { impl<'a> From<&'a Path> for Section { fn from(value: &'a Path) -> Self { for section in Self::variants() { - if value.file_stem().and_then(|v| v.to_str()) == Some(§ion.to_string()) { - return *section; + if let Some(file_stem) = value.file_stem().and_then(|v| v.to_str()) { + if file_stem.starts_with(§ion.to_string().to_lowercase()) { + return *section; + } } } Self::Net @@ -65,3 +67,20 @@ impl Section { ] } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_sysctl_section() { + assert_eq!(Section::Net, Section::from(String::from("net.xyz"))); + assert_eq!(Section::User, Section::from(String::from("user.aaa.bbb"))); + assert_eq!(Section::Unknown, Section::from(String::from("test"))); + assert_eq!(Section::Vm, Section::from(Path::new("/etc/vm.txt"))); + assert_eq!( + Section::Kernel, + Section::from(Path::new("/etc/kernel.tar.gz")) + ); + } +}