Skip to content

Commit

Permalink
Use diff method directly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schneems committed Dec 12, 2024
1 parent dfc1a8b commit 1216762
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 75 deletions.
12 changes: 5 additions & 7 deletions buildpacks/ruby/src/layers/bundle_download_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>>(),
vec!["Bundler version (`2.3.5` to `2.3.6`)"]
Expand Down
64 changes: 30 additions & 34 deletions buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,52 +356,48 @@ mod test {
)
.unwrap(),
};
assert_eq!(CacheDiff::diff(&old, &old), Vec::<String>::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::<String>::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<String>>(),
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<String>>(),
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<String>>(),
vec!["CPU Architecture (`amd64` to `arm64`)".to_string()]
Expand Down
64 changes: 30 additions & 34 deletions buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,52 +322,48 @@ version = "3.1.3"
},
cpu_architecture: "amd64".to_string(),
};
assert_eq!(CacheDiff::diff(&old, &old), Vec::<String>::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::<String>::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<String>>(),
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<String>>(),
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<String>>(),
vec!["CPU architecture (`amd64` to `arm64`)".to_string()]
Expand All @@ -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::<String>::new());

cached_layer_write_metadata(layer_name!("ruby"), &context, &old).unwrap();
Expand All @@ -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();
Expand Down

0 comments on commit 1216762

Please sign in to comment.