Skip to content

Commit

Permalink
Exercise same interface used in file
Browse files Browse the repository at this point in the history
In the ruby_install_layer we're exercising `cached_layer_write_metadata` but we were testing `restored_layer_action` which is called currently but might not be in the future via refactoring. This change asserts the behavior we want while using the exact same interface we are currently using.
  • Loading branch information
schneems committed Oct 1, 2024
1 parent 76d301c commit b556b9a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub(crate) enum RubyInstallError {

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

use super::*;

Expand Down Expand Up @@ -325,30 +325,35 @@ version = "3.1.3"

#[test]
fn test_ruby_version_difference_clears_cache() {
let temp = tempfile::tempdir().unwrap();
let context = temp_build_context::<RubyBuildpack>(temp.path());
let old = Metadata {
ruby_version: ResolvedRubyVersion("2.7.2".to_string()),
distro_name: "ubuntu".to_string(),
distro_version: "20.04".to_string(),
cpu_architecture: "x86_64".to_string(),
};
let differences = old.diff(&old);
let actual = restored_layer_action(&old, &old);
assert!(matches!(
actual,
(libcnb::layer::RestoredLayerAction::KeepLayer, _)
));

assert_eq!(differences, Vec::<String>::new());

cached_layer_write_metadata(layer_name!("ruby"), &context, &old).unwrap();
let result = cached_layer_write_metadata(layer_name!("ruby"), &context, &old).unwrap();
let actual = result.state;
assert!(matches!(actual, LayerState::Restored { .. }));

let now = Metadata {
ruby_version: ResolvedRubyVersion("3.0.0".to_string()),
..old.clone()
};
let differences = now.diff(&old);
assert_eq!(differences.len(), 1);

let actual = restored_layer_action(&old, &now);
let result = cached_layer_write_metadata(layer_name!("ruby"), &context, &now).unwrap();
assert!(matches!(
actual,
(libcnb::layer::RestoredLayerAction::DeleteLayer, _)
result.state,
LayerState::Empty {
cause: EmptyLayerCause::RestoredLayerAction { .. }
}
));
}
}

0 comments on commit b556b9a

Please sign in to comment.