Skip to content

Commit

Permalink
test: is_major_bump
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotsx committed Apr 28, 2024
1 parent 53a2cb6 commit f910363
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ pub mod release;
pub mod schemas;
pub mod seed;
pub mod system;

#[cfg(test)]
mod tests {
mod release;
}
14 changes: 6 additions & 8 deletions src/utils/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ pub fn get_latest_release() -> Result<String, Error> {
if response.status().is_success() {
let latest = response.json::<GithubRelease>();

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,
Expand Down
34 changes: 34 additions & 0 deletions src/utils/tests/release.rs
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit f910363

Please sign in to comment.