From 12167629cfb9961fcd821d98902f479963da9bab Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 12 Dec 2024 16:07:54 -0600 Subject: [PATCH] Use diff method directly In the refactor we had two `diff` methods, now there's only one so we can use it instead of having to reference the trait. This shaves off some lines of the total diff. --- .../ruby/src/layers/bundle_download_layer.rs | 12 ++-- .../ruby/src/layers/bundle_install_layer.rs | 64 +++++++++---------- .../ruby/src/layers/ruby_install_layer.rs | 64 +++++++++---------- 3 files changed, 65 insertions(+), 75 deletions(-) diff --git a/buildpacks/ruby/src/layers/bundle_download_layer.rs b/buildpacks/ruby/src/layers/bundle_download_layer.rs index fd424f9..2bccafa 100644 --- a/buildpacks/ruby/src/layers/bundle_download_layer.rs +++ b/buildpacks/ruby/src/layers/bundle_download_layer.rs @@ -129,14 +129,12 @@ mod test { let old = Metadata { version: ResolvedBundlerVersion("2.3.5".to_string()), }; - assert!(CacheDiff::diff(&old, &old).is_empty()); + assert!(old.diff(&old).is_empty()); - let diff = CacheDiff::diff( - &Metadata { - version: ResolvedBundlerVersion("2.3.6".to_string()), - }, - &old, - ); + let diff = &Metadata { + version: ResolvedBundlerVersion("2.3.6".to_string()), + } + .diff(&old); assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["Bundler version (`2.3.5` to `2.3.6`)"] diff --git a/buildpacks/ruby/src/layers/bundle_install_layer.rs b/buildpacks/ruby/src/layers/bundle_install_layer.rs index 2191047..9d11c60 100644 --- a/buildpacks/ruby/src/layers/bundle_install_layer.rs +++ b/buildpacks/ruby/src/layers/bundle_install_layer.rs @@ -356,52 +356,48 @@ mod test { ) .unwrap(), }; - assert_eq!(CacheDiff::diff(&old, &old), Vec::::new()); - - let diff = CacheDiff::diff( - &Metadata { - ruby_version: ResolvedRubyVersion("3.5.5".to_string()), - os_distribution: old.os_distribution.clone(), - cpu_architecture: old.cpu_architecture.clone(), - force_bundle_install_key: old.force_bundle_install_key.clone(), - digest: old.digest.clone(), - }, - &old, - ); + assert_eq!(old.diff(&old), Vec::::new()); + + let diff = &Metadata { + ruby_version: ResolvedRubyVersion("3.5.5".to_string()), + os_distribution: old.os_distribution.clone(), + cpu_architecture: old.cpu_architecture.clone(), + force_bundle_install_key: old.force_bundle_install_key.clone(), + digest: old.digest.clone(), + } + .diff(&old); + assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["Ruby version (`3.5.3` to `3.5.5`)".to_string()] ); - let diff = CacheDiff::diff( - &Metadata { - ruby_version: old.ruby_version.clone(), - os_distribution: OsDistribution { - name: "alpine".to_string(), - version: "3.20.0".to_string(), - }, - cpu_architecture: old.cpu_architecture.clone(), - force_bundle_install_key: old.force_bundle_install_key.clone(), - digest: old.digest.clone(), + let diff = &Metadata { + ruby_version: old.ruby_version.clone(), + os_distribution: OsDistribution { + name: "alpine".to_string(), + version: "3.20.0".to_string(), }, - &old, - ); + cpu_architecture: old.cpu_architecture.clone(), + force_bundle_install_key: old.force_bundle_install_key.clone(), + digest: old.digest.clone(), + } + .diff(&old); assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["OS Distribution (`ubuntu 20.04` to `alpine 3.20.0`)".to_string()] ); - let diff = CacheDiff::diff( - &Metadata { - ruby_version: old.ruby_version.clone(), - os_distribution: old.os_distribution.clone(), - cpu_architecture: "arm64".to_string(), - force_bundle_install_key: old.force_bundle_install_key.clone(), - digest: old.digest.clone(), - }, - &old, - ); + let diff = &Metadata { + ruby_version: old.ruby_version.clone(), + os_distribution: old.os_distribution.clone(), + cpu_architecture: "arm64".to_string(), + force_bundle_install_key: old.force_bundle_install_key.clone(), + digest: old.digest.clone(), + } + .diff(&old); + assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["CPU Architecture (`amd64` to `arm64`)".to_string()] diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 725c2ec..3dc5090 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -322,52 +322,48 @@ version = "3.1.3" }, cpu_architecture: "amd64".to_string(), }; - assert_eq!(CacheDiff::diff(&old, &old), Vec::::new()); - - let diff = CacheDiff::diff( - &Metadata { - ruby_version: ResolvedRubyVersion("3.5.5".to_string()), - os_distribution: OsDistribution { - name: "ubuntu".to_string(), - version: "20.04".to_string(), - }, - cpu_architecture: old.cpu_architecture.clone(), + assert_eq!(old.diff(&old), Vec::::new()); + + let diff = &Metadata { + ruby_version: ResolvedRubyVersion("3.5.5".to_string()), + os_distribution: OsDistribution { + name: "ubuntu".to_string(), + version: "20.04".to_string(), }, - &old, - ); + cpu_architecture: old.cpu_architecture.clone(), + } + .diff(&old); + assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["Ruby version (`3.5.3` to `3.5.5`)".to_string()] ); - let diff = CacheDiff::diff( - &Metadata { - ruby_version: old.ruby_version.clone(), - os_distribution: OsDistribution { - name: "alpine".to_string(), - version: "3.20.0".to_string(), - }, - cpu_architecture: old.cpu_architecture.clone(), + let diff = &Metadata { + ruby_version: old.ruby_version.clone(), + os_distribution: OsDistribution { + name: "alpine".to_string(), + version: "3.20.0".to_string(), }, - &old, - ); + cpu_architecture: old.cpu_architecture.clone(), + } + .diff(&old); assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["OS Distribution (`ubuntu 20.04` to `alpine 3.20.0`)".to_string()] ); - let diff = CacheDiff::diff( - &Metadata { - ruby_version: old.ruby_version.clone(), - os_distribution: OsDistribution { - name: old.os_distribution.name.clone(), - version: old.os_distribution.version.clone(), - }, - cpu_architecture: "arm64".to_string(), + let diff = &Metadata { + ruby_version: old.ruby_version.clone(), + os_distribution: OsDistribution { + name: old.os_distribution.name.clone(), + version: old.os_distribution.version.clone(), }, - &old, - ); + cpu_architecture: "arm64".to_string(), + } + .diff(&old); + assert_eq!( diff.iter().map(strip_ansi).collect::>(), vec!["CPU architecture (`amd64` to `arm64`)".to_string()] @@ -386,7 +382,7 @@ version = "3.1.3" }, cpu_architecture: "x86_64".to_string(), }; - let differences = CacheDiff::diff(&old, &old); + let differences = old.diff(&old); assert_eq!(differences, Vec::::new()); cached_layer_write_metadata(layer_name!("ruby"), &context, &old).unwrap(); @@ -398,7 +394,7 @@ version = "3.1.3" ruby_version: ResolvedRubyVersion("3.0.0".to_string()), ..old.clone() }; - let differences = CacheDiff::diff(&now, &old); + let differences = now.diff(&old); assert_eq!(differences.len(), 1); let result = cached_layer_write_metadata(layer_name!("ruby"), &context, &now).unwrap();