Skip to content

Commit fc35dc1

Browse files
committed
Make PVM kernel test hermetic
1 parent d72a8cf commit fc35dc1

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

crates/port-cli/tests/artifact_commands.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,29 @@ fn install_fake_oras_script(root: &Path, body: &str) -> PathBuf {
329329
script_path
330330
}
331331

332+
fn install_fake_pvm_kernel_flake(root: &Path) -> PathBuf {
333+
let flake_root = root.join("pvm-builds");
334+
let kernel_root = flake_root.join("kernel");
335+
fs::create_dir_all(&kernel_root).expect("fake pvm kernel fixture should exist");
336+
fs::write(kernel_root.join("vmlinux"), "demo-pvm-kernel-bytes")
337+
.expect("fake pvm kernel should write");
338+
fs::write(
339+
flake_root.join("flake.nix"),
340+
r#"{
341+
description = "Port CLI PVM kernel fixture";
342+
outputs = { self }: {
343+
packages.x86_64-linux.linux-port-pvm-guest = builtins.path {
344+
path = ./kernel;
345+
name = "linux-port-pvm-guest-fixture";
346+
};
347+
};
348+
}
349+
"#,
350+
)
351+
.expect("fake pvm kernel flake should write");
352+
flake_root
353+
}
354+
332355
#[test]
333356
fn cli_artifact_list_reports_local_and_cached_variants() {
334357
let temp = tempdir().expect("tempdir should exist");
@@ -928,6 +951,7 @@ fn cli_artifact_build_and_validate_selected_pvm_kernel_variant() {
928951
let local_root = temp.path().join("local-artifacts");
929952
let store_root = temp.path().join("artifact-store");
930953
let cache_root = temp.path().join("artifact-cache");
954+
let pvm_build_flake_ref = install_fake_pvm_kernel_flake(temp.path());
931955

932956
let mut config = PortConfig::sample();
933957
let (kernel_path, _, _) = configure_kernel_paths(
@@ -952,6 +976,7 @@ fn cli_artifact_build_and_validate_selected_pvm_kernel_variant() {
952976
.arg("firecracker")
953977
.arg("--protection-mode")
954978
.arg("pvm")
979+
.env("PORT_PVM_BUILD_FLAKE_REF", &pvm_build_flake_ref)
955980
.output()
956981
.expect("build command");
957982
assert!(
@@ -988,6 +1013,7 @@ fn cli_artifact_build_and_validate_selected_pvm_kernel_variant() {
9881013
.arg("firecracker")
9891014
.arg("--protection-mode")
9901015
.arg("pvm")
1016+
.env("PORT_PVM_BUILD_FLAKE_REF", &pvm_build_flake_ref)
9911017
.output()
9921018
.expect("validate command");
9931019
assert!(

0 commit comments

Comments
 (0)