diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2c2ee56..f0acfce 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,3 +5,8 @@ pub mod release; pub mod schemas; pub mod seed; pub mod system; + +#[cfg(test)] +mod tests { + mod release; +} diff --git a/src/utils/release.rs b/src/utils/release.rs index 3ccaa26..98d9bd2 100644 --- a/src/utils/release.rs +++ b/src/utils/release.rs @@ -40,14 +40,12 @@ pub fn get_latest_release() -> Result { if response.status().is_success() { let latest = response.json::(); - if latest.is_err() { - return Err(Error::new( - ErrorKind::Other, - format!("Failed to parse latest release: {:?}", latest.err()), - )); - } else { - return Ok(latest.unwrap().tag_name[1..].to_string()); - } + return match latest { + Ok(latest) => Ok(latest.tag_name[1..].to_string()), + Err(e) => { + return Err(Error::new(ErrorKind::Other, format!("Failed to parse latest release: {:?}", e))); + } + }; } else { return Err(Error::new( ErrorKind::Other, diff --git a/src/utils/tests/release.rs b/src/utils/tests/release.rs new file mode 100644 index 0000000..4f3f826 --- /dev/null +++ b/src/utils/tests/release.rs @@ -0,0 +1,34 @@ +#[cfg(test)] +mod test_is_major_bump { + use crate::utils::release::is_major_bump; + + #[test] + fn test_nightly() { + assert!(!is_major_bump("1.2.3", "nightly")); + } + + #[test] + fn test_major_bump() { + assert!(is_major_bump("1.2.3", "2.0.0")); + } + + #[test] + fn test_minor_bump() { + assert!(!is_major_bump("1.2.3", "1.3.0")); + } + + #[test] + fn test_patch_bump() { + assert!(!is_major_bump("1.2.3", "1.2.4")); + } + + #[test] + fn test_no_bump() { + assert!(!is_major_bump("1.2.3", "1.2.3")); + } + + #[test] + fn test_downgrade() { + assert!(!is_major_bump("2.0.0", "1.9.9")); + } +}