Skip to content

Commit 033dc0d

Browse files
committed
Test applying OCI deltas with the ostree backend
Three tests covering the whole path from a delta on disk to an imported image, at increasing degrees of realism: `test_apply_delta_whole_layers` builds a delta whose patches are the target layers carried verbatim. The format allows that, and the layer reconstruction dispatches on media type, so this exercises parsing, validation, source lookup and the import while needing no external tooling - it runs everywhere. `test_apply_delta_chunked` and `test_apply_delta_derived` use the real `oci-delta` to build the delta, and skip themselves when it is not installed. The first covers an ostree-native image, whose layers are made of repo objects under `sysroot/ostree/` that do not exist in the commit's file tree - it passes only because oci-delta is told never to ask for one. The second covers a derived layer, an ordinary root filesystem tar, which is the case that actually drives `OstreeDataSource`; the file it patches lives at `/etc/bigconf`, i.e. at a path the importer relocates, and the test asserts both that it lands at `/usr/etc/bigconf` and that the patch is far smaller than the layer, which it can only be if the content really was read back out of the source commit. `oci-delta` goes in a new optional package list, because it is not available on every distribution we build on. Assisted-by: AI Signed-off-by: Alexander Larsson <alexl@redhat.com>
1 parent 9d3cb1e commit 033dc0d

5 files changed

Lines changed: 454 additions & 5 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Packages that are only needed by some tests, and that we do not require to
2+
# be available everywhere we build. Anything listed here must be optional:
3+
# install-buildroot carries on without it, and the tests that use it skip
4+
# themselves when it is absent.
5+
#
6+
# Generates the deltas the `--from-delta` tests apply.
7+
oci-delta

‎contrib/packaging/install-buildroot‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ dnf -y distro-sync ostree{,-libs} systemd
2121
dnf -y builddep bootc.spec
2222
# And extra packages
2323
grep -Ev -e '^#' fedora-extra.txt | xargs dnf -y install
24+
# Packages that only enable extra tests, and are not in every distribution we
25+
# build on. The tests that want these skip themselves when they are missing.
26+
for pkg in $(grep -Ev -e '^#' fedora-extra-optional.txt); do
27+
dnf -y install "$pkg" || echo "warning: optional package $pkg is unavailable"
28+
done

‎crates/lib/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ uuid = { version = "1.8.0", features = ["v4"] }
7979
uapi-version = "0.4.0"
8080

8181
[dev-dependencies]
82+
# For the ostree/container test fixtures
83+
ostree-ext = { path = "../ostree-ext", features = ["bootc", "internal-testing-api"] }
8284
similar-asserts = { workspace = true }
8385
static_assertions = { workspace = true }
8486

‎crates/lib/src/delta.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,14 @@ pub(crate) mod tests {
323323
use ocidir::oci_spec::image::{ImageConfigurationBuilder, ImageManifestBuilder, RootFsBuilder};
324324
use std::collections::HashMap;
325325

326-
const DELTA_CONTENT: &str = "io.github.containers.delta.content";
327-
const DELTA_TO: &str = "io.github.containers.delta.to";
328-
const DELTA_SOURCE_CONFIG: &str = "io.github.containers.delta.source-config";
326+
pub(crate) const DELTA_CONTENT: &str = "io.github.containers.delta.content";
327+
pub(crate) const DELTA_TO: &str = "io.github.containers.delta.to";
328+
pub(crate) const DELTA_SOURCE_CONFIG: &str = "io.github.containers.delta.source-config";
329329
const TAR_DIFF: &str = "application/vnd.tar-diff";
330330
const ZERO_DIGEST: &str =
331331
"sha256:0000000000000000000000000000000000000000000000000000000000000000";
332332

333-
fn blob(oci: &OciDir, data: &[u8], media_type: MediaType) -> Descriptor {
333+
pub(crate) fn blob(oci: &OciDir, data: &[u8], media_type: MediaType) -> Descriptor {
334334
let mut w = oci.create_blob().unwrap();
335335
std::io::Write::write_all(&mut w, data).unwrap();
336336
w.complete()
@@ -354,7 +354,7 @@ pub(crate) mod tests {
354354
.unwrap()
355355
}
356356

357-
fn annotate(mut desc: Descriptor, annotations: &[(&str, &str)]) -> Descriptor {
357+
pub(crate) fn annotate(mut desc: Descriptor, annotations: &[(&str, &str)]) -> Descriptor {
358358
desc.set_annotations(Some(
359359
annotations
360360
.iter()

0 commit comments

Comments
 (0)