Skip to content

Commit fde1cc5

Browse files
committed
test(oci): capture fixture image identity before sandbox creation
Signed-off-by: Evan Lezar <[email protected]>
1 parent 2bb7f66 commit fde1cc5

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎tests/suites/features/oci-image/tests/oci_image.rs‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ USER app
162162
"--name",
163163
&name,
164164
"--from",
165-
&image,
165+
&image.tag,
166166
"--no-tty",
167167
"--",
168168
"sh",
@@ -285,7 +285,7 @@ fn workspace_checks(identity: &str, workspace: &str, image_file: bool) -> String
285285
async fn create_sandbox(
286286
runner: &mut OpenShellRunner,
287287
short: &str,
288-
image: &str,
288+
image: &TestImage,
289289
policy: Option<&str>,
290290
checks: &str,
291291
) -> Result<String, String> {
@@ -294,7 +294,7 @@ async fn create_sandbox(
294294
"(set -eu; {checks} touch main-write) >/tmp/oci-main.log 2>&1; \
295295
echo $? >/tmp/oci-main.status; exec sleep infinity"
296296
);
297-
let mut args = vec!["sandbox", "create", "--name", &name, "--from", image];
297+
let mut args = vec!["sandbox", "create", "--name", &name, "--from", &image.tag];
298298
if let Some(policy) = policy {
299299
args.extend(["--policy", policy]);
300300
}
@@ -417,27 +417,27 @@ async fn file_transfer_uses_workspace(
417417
}
418418

419419
/// Check the containers the driver created for `sandbox`. The workload runs
420-
/// the image ID inspected before creation, so retagging cannot swap it, and
420+
/// the image ID captured after the fixture build, before sandbox creation, and
421421
/// starts directly as the sandbox `identity` without a network or the
422422
/// supervisor's credentials. The supervisor runs in a separate non-root
423423
/// container.
424424
fn container_checks(
425425
engine: &Engine,
426426
sandbox: &str,
427-
image: &str,
427+
image: &TestImage,
428428
identity: &str,
429429
) -> Result<(), String> {
430430
let workload = engine.container_for_role(sandbox, "sandbox")?;
431431
let supervisor = engine.container_for_role(sandbox, "supervisor")?;
432432
if workload == supervisor {
433433
return Err(format!("{sandbox} has no separate supervisor container"));
434434
}
435-
let image_id = engine.output(&["image", "inspect", "--format", "{{.Id}}", image])?;
436435
let launched = engine.inspect_container(&workload, "{{.Image}}")?;
437436
let digest = |id: &str| id.trim_start_matches("sha256:").to_string();
438-
if digest(&launched) != digest(&image_id) {
437+
if digest(&launched) != digest(&image.id) {
439438
return Err(format!(
440-
"workload launched image {launched}, expected the inspected {image_id}"
439+
"workload launched image {launched}, expected the built image {}",
440+
image.id
441441
));
442442
}
443443
let user = engine.inspect_container(&workload, "{{.Config.User}}")?;
@@ -507,6 +507,12 @@ async fn exec(
507507
.await
508508
}
509509

510+
/// A built fixture's mutable tag and image ID captured before sandbox creation.
511+
struct TestImage {
512+
tag: String,
513+
id: String,
514+
}
515+
510516
/// The gateway's container engine. Images it builds for a scenario are
511517
/// removed by `run` after sandbox cleanup.
512518
struct Engine {
@@ -528,8 +534,8 @@ impl Engine {
528534
}
529535
}
530536

531-
/// Build `containerfile` and return the image tag.
532-
fn build_image(&mut self, name: &str, containerfile: &str) -> Result<String, String> {
537+
/// Build `containerfile` and capture its image ID before sandbox creation.
538+
fn build_image(&mut self, name: &str, containerfile: &str) -> Result<TestImage, String> {
533539
let context = tempfile::tempdir().map_err(|error| format!("create context: {error}"))?;
534540
let file = context.path().join("Containerfile");
535541
std::fs::write(&file, containerfile)
@@ -545,7 +551,8 @@ impl Engine {
545551
])?;
546552
// A failed build leaves no tag to remove.
547553
self.images.push(tag.clone());
548-
Ok(tag)
554+
let id = self.output(&["image", "inspect", "--format", "{{.Id}}", &tag])?;
555+
Ok(TestImage { tag, id })
549556
}
550557

551558
/// Remove every built image, returning one error per failed removal.

0 commit comments

Comments
 (0)