Skip to content

Commit

Permalink
fix: mend clippy error
Browse files Browse the repository at this point in the history
  • Loading branch information
exincore committed Jan 1, 2023
1 parent 65d018d commit 4059955
Showing 1 changed file with 39 additions and 43 deletions.
82 changes: 39 additions & 43 deletions os_info/src/linux/file_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn retrieve(distributions: &[ReleaseInfo], root: &str) -> Option<Info> {
edition,
codename,
bitness: Bitness::Unknown,
..Default::default()
});
}

Expand Down Expand Up @@ -161,13 +160,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [
.map(Version::from_string)
},
edition: |release| Matcher::KeyValue { key: "VARIANT" }.find(release),
codename: |release| {
Matcher::KeyValue {
key: "VERSION_CODENAME",
}
.find(release)
.filter(|v| !v.is_empty())
},
codename: |release| Matcher::KeyValue { key: "VERSION_CODENAME" }.find(release).filter(|v| !v.is_empty()),
},
// Older distributions must have their specific release file parsed.
ReleaseInfo {
Expand Down Expand Up @@ -228,13 +221,13 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [
#[cfg(test)]
mod tests {
use super::*;
use lazy_static::lazy_static;
use pretty_assertions::assert_eq;

#[test]
fn retrieve() {
let expected_pairs = [
lazy_static! {
static ref EXPECTED_PAIRS: [(String, Option<Info>); 29] = [
(
"src/linux/tests/Alpine/3.17.0",
"src/linux/tests/Alpine/3.17.0".to_owned(),
Some(Info {
os_type: Type::Alpine,
version: Version::Semantic(3, 17, 0),
Expand All @@ -243,31 +236,31 @@ mod tests {
),
(
// Isolated alpine-release test
"src/linux/tests/Alpine/3.17.0/alpine-release",
"src/linux/tests/Alpine/3.17.0/alpine-release".to_owned(),
Some(Info {
os_type: Type::Alpine,
version: Version::Semantic(3, 17, 0),
..Default::default()
}),
),
(
"src/linux/tests/Amazon/2018.3.0",
"src/linux/tests/Amazon/2018.3.0".to_owned(),
Some(Info {
os_type: Type::Amazon,
version: Version::Semantic(2018, 3, 0),
..Default::default()
}),
),
(
"src/linux/tests/Amazon/2.0.0",
"src/linux/tests/Amazon/2.0.0".to_owned(),
Some(Info {
os_type: Type::Amazon,
version: Version::Semantic(2, 0, 0),
..Default::default()
}),
),
(
"src/linux/tests/Arch/rolling",
"src/linux/tests/Arch/rolling".to_owned(),
Some(Info {
os_type: Type::Arch,
// TODO: Should be Version::Rolling
Expand All @@ -277,15 +270,15 @@ mod tests {
),
(
// CentOS Linux
"src/linux/tests/CentOS/7.0.0",
"src/linux/tests/CentOS/7.0.0".to_owned(),
Some(Info {
os_type: Type::CentOS,
version: Version::Semantic(7, 0, 0),
..Default::default()
}),
),
(
"src/linux/tests/CentOS/7.0.0/centos-release",
"src/linux/tests/CentOS/7.0.0/centos-release".to_owned(),
Some(Info {
os_type: Type::CentOS,
version: Version::Semantic(7, 0, 0),
Expand All @@ -294,15 +287,15 @@ mod tests {
),
(
// CentOS Stream
"src/linux/tests/CentOS/8.0.0",
"src/linux/tests/CentOS/8.0.0".to_owned(),
Some(Info {
os_type: Type::CentOS,
version: Version::Semantic(8, 0, 0),
..Default::default()
}),
),
(
"src/linux/tests/EndeavourOS/rolling",
"src/linux/tests/EndeavourOS/rolling".to_owned(),
Some(Info {
os_type: Type::EndeavourOS,
// TODO: Should be Version::Rolling
Expand All @@ -311,7 +304,7 @@ mod tests {
}),
),
(
"src/linux/tests/Fedora/32.0.0/cloud",
"src/linux/tests/Fedora/32.0.0/cloud".to_owned(),
Some(Info {
os_type: Type::Fedora,
version: Version::Semantic(32, 0, 0),
Expand All @@ -320,7 +313,7 @@ mod tests {
}),
),
(
"src/linux/tests/Fedora/35.0.0/workstation",
"src/linux/tests/Fedora/35.0.0/workstation".to_owned(),
Some(Info {
os_type: Type::Fedora,
version: Version::Semantic(35, 0, 0),
Expand All @@ -329,15 +322,15 @@ mod tests {
}),
),
(
"src/linux/tests/Fedora/35.0.0/workstation/fedora-release",
"src/linux/tests/Fedora/35.0.0/workstation/fedora-release".to_owned(),
Some(Info {
os_type: Type::Fedora,
version: Version::Semantic(35, 0, 0),
..Default::default()
}),
),
(
"src/linux/tests/Garuda/rolling",
"src/linux/tests/Garuda/rolling".to_owned(),
Some(Info {
os_type: Type::Garuda,
// TODO: Should be Version::Rolling
Expand All @@ -346,15 +339,15 @@ mod tests {
}),
),
(
"src/linux/tests/Mariner/2.0.20220210",
"src/linux/tests/Mariner/2.0.20220210".to_owned(),
Some(Info {
os_type: Type::Mariner,
version: Version::Semantic(2, 0, 20220210),
..Default::default()
}),
),
(
"src/linux/tests/Mint/20.0.0",
"src/linux/tests/Mint/20.0.0".to_owned(),
Some(Info {
os_type: Type::Mint,
version: Version::Semantic(20, 0, 0),
Expand All @@ -363,19 +356,19 @@ mod tests {
}),
),
(
"src/linux/tests/NixOS/21.05pre275822.916ee862e87",
"src/linux/tests/NixOS/21.05pre275822.916ee862e87".to_owned(),
Some(Info {
os_type: Type::NixOS,
version: Version::Custom("21.05pre275822.916ee862e87".to_owned()),
codename: Some("okapi".to_owned()),
..Default::default()
}),
),
("src/linux/tests/none_invalid_os_release", None),
("src/linux/tests/none_no_path", None),
("src/linux/tests/none_no_release", None),
("src/linux/tests/none_invalid_os_release".to_owned(), None),
("src/linux/tests/none_no_path".to_owned(), None),
("src/linux/tests/none_no_release".to_owned(), None),
(
"src/linux/tests/OracleLinux/8.1.0/server",
"src/linux/tests/OracleLinux/8.1.0/server".to_owned(),
Some(Info {
os_type: Type::OracleLinux,
version: Version::Semantic(8, 1, 0),
Expand All @@ -384,7 +377,7 @@ mod tests {
}),
),
(
"src/linux/tests/Pop/22.4.0",
"src/linux/tests/Pop/22.4.0".to_owned(),
Some(Info {
os_type: Type::Pop,
version: Version::Semantic(22, 4, 0),
Expand All @@ -393,7 +386,7 @@ mod tests {
}),
),
(
"src/linux/tests/Raspbian/10.0.0",
"src/linux/tests/Raspbian/10.0.0".to_owned(),
Some(Info {
os_type: Type::Raspbian,
version: Version::Semantic(10, 0, 0),
Expand All @@ -402,15 +395,15 @@ mod tests {
}),
),
(
"src/linux/tests/RedHatEnterprise/8.2.0",
"src/linux/tests/RedHatEnterprise/8.2.0".to_owned(),
Some(Info {
os_type: Type::RedHatEnterprise,
version: Version::Semantic(8, 2, 0),
..Default::default()
}),
),
(
"src/linux/tests/RedHatEnterprise/7.9.0/server",
"src/linux/tests/RedHatEnterprise/7.9.0/server".to_owned(),
Some(Info {
os_type: Type::RedHatEnterprise,
version: Version::Semantic(7, 9, 0),
Expand All @@ -419,15 +412,15 @@ mod tests {
}),
),
(
"src/linux/tests/RedHatEnterprise/7.9.0/server/redhat-release",
"src/linux/tests/RedHatEnterprise/7.9.0/server/redhat-release".to_owned(),
Some(Info {
os_type: Type::RedHatEnterprise,
version: Version::Semantic(7, 9, 0),
..Default::default()
}),
),
(
"src/linux/tests/Solus/4.3.0",
"src/linux/tests/Solus/4.3.0".to_owned(),
Some(Info {
os_type: Type::Solus,
version: Version::Semantic(4, 3, 0),
Expand All @@ -436,23 +429,23 @@ mod tests {
}),
),
(
"src/linux/tests/SUSE/12.5.0",
"src/linux/tests/SUSE/12.5.0".to_owned(),
Some(Info {
os_type: Type::SUSE,
version: Version::Semantic(12, 5, 0),
..Default::default()
}),
),
(
"src/linux/tests/SUSE/15.2.0",
"src/linux/tests/SUSE/15.2.0".to_owned(),
Some(Info {
os_type: Type::SUSE,
version: Version::Semantic(15, 2, 0),
..Default::default()
}),
),
(
"src/linux/tests/Ubuntu/18.10.0",
"src/linux/tests/Ubuntu/18.10.0".to_owned(),
Some(Info {
os_type: Type::Ubuntu,
version: Version::Semantic(18, 10, 0),
Expand All @@ -461,13 +454,16 @@ mod tests {
}),
),
];
}

for (root, expected) in expected_pairs {
#[test]
fn retrieve() {
for (root, expected) in EXPECTED_PAIRS.iter() {
assert_eq!(
super::retrieve(&DISTRIBUTIONS, root),
&super::retrieve(&DISTRIBUTIONS, &root),
expected,
"the parsed release files (left) at `{}` did not match expected values (right)",
root
&root
)
}
}
Expand Down

0 comments on commit 4059955

Please sign in to comment.