From b556b9aa6dfced95f07ca84ee60cee03f6fccd5f Mon Sep 17 00:00:00 2001 From: Schneems Date: Mon, 30 Sep 2024 15:40:56 -0500 Subject: [PATCH] Exercise same interface used in file 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. --- .../ruby/src/layers/ruby_install_layer.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 339fab4b..36b35082 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -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::*; @@ -325,6 +325,8 @@ version = "3.1.3" #[test] fn test_ruby_version_difference_clears_cache() { + let temp = tempfile::tempdir().unwrap(); + let context = temp_build_context::(temp.path()); let old = Metadata { ruby_version: ResolvedRubyVersion("2.7.2".to_string()), distro_name: "ubuntu".to_string(), @@ -332,23 +334,26 @@ version = "3.1.3" 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::::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 { .. } + } )); } }