Skip to content

Commit

Permalink
Assert all difference output
Browse files Browse the repository at this point in the history
- Ensures each of these cases where the vec is not empty will clear the cache.
- Makes it easier for reviewers to see the output as a user would see it.
  • Loading branch information
schneems committed Oct 2, 2024
1 parent 38e46e2 commit a01ceac
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub(crate) enum RubyInstallError {

#[cfg(test)]
mod tests {
use crate::layers::shared::temp_build_context;
use crate::layers::shared::{strip_ansi, temp_build_context};

use super::*;

Expand Down Expand Up @@ -316,6 +316,54 @@ version = "3.1.3"
);
}

#[test]
fn metadata_diff_messages() {
let old = Metadata {
ruby_version: ResolvedRubyVersion("3.5.3".to_string()),
distro_name: "ubuntu".to_string(),
distro_version: "20.04".to_string(),
cpu_architecture: "amd64".to_string(),
};
assert_eq!(old.diff(&old), Vec::<String>::new());

let diff = Metadata {
ruby_version: ResolvedRubyVersion("3.5.5".to_string()),
distro_name: old.distro_name.clone(),
distro_version: old.distro_version.clone(),
cpu_architecture: old.cpu_architecture.clone(),
}
.diff(&old);
assert_eq!(
diff.iter().map(strip_ansi).collect::<Vec<String>>(),
vec!["Ruby version (`3.5.3` to `3.5.5`)".to_string()]
);

let diff = Metadata {
ruby_version: old.ruby_version.clone(),
distro_name: "alpine".to_string(),
distro_version: "3.20.0".to_string(),
cpu_architecture: old.cpu_architecture.clone(),
}
.diff(&old);

assert_eq!(
diff.iter().map(strip_ansi).collect::<Vec<String>>(),
vec!["Distribution (`ubuntu 20.04` to `alpine 3.20.0`)".to_string()]
);

let diff = Metadata {
ruby_version: old.ruby_version.clone(),
distro_name: old.distro_name.clone(),
distro_version: old.distro_version.clone(),
cpu_architecture: "arm64".to_string(),
}
.diff(&old);
assert_eq!(
diff.iter().map(strip_ansi).collect::<Vec<String>>(),
vec!["CPU architecture (`amd64` to `arm64`)".to_string()]
);
}

#[test]
fn test_ruby_version_difference_clears_cache() {
let temp = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit a01ceac

Please sign in to comment.