83 lines
2.5 KiB
Plaintext
83 lines
2.5 KiB
Plaintext
// Basic tests for QCOW2 SAL (offline, will skip if qemu-img is not present)
|
|
|
|
print("=== QCOW2 Basic Tests ===");
|
|
|
|
// Dependency check
|
|
let qemu = which("qemu-img");
|
|
if qemu == () {
|
|
print("⚠️ qemu-img not available - skipping QCOW2 tests");
|
|
print("Install qemu-utils (Debian/Ubuntu) or QEMU tools for your distro.");
|
|
print("=== QCOW2 Tests Skipped ===");
|
|
exit();
|
|
}
|
|
|
|
// Helper: unique temp path (use monotonic timestamp; avoid shell quoting issues)
|
|
let now = run_silent("date +%s%N");
|
|
let suffix = if now.success && now.stdout != "" { now.stdout.trim() } else { "100000" };
|
|
let img_path = `/tmp/qcow2_test_${suffix}.img`;
|
|
|
|
print("\n--- Test 1: Create image ---");
|
|
try {
|
|
let created_path = qcow2_create(img_path, 1);
|
|
// created_path should equal img_path
|
|
print(`✓ Created qcow2: ${created_path}`);
|
|
} catch (err) {
|
|
print(`❌ Create failed: ${err}`);
|
|
exit();
|
|
}
|
|
|
|
print("\n--- Test 2: Info ---");
|
|
let info;
|
|
try {
|
|
info = qcow2_info(img_path);
|
|
} catch (err) {
|
|
print(`❌ Info failed: ${err}`);
|
|
exit();
|
|
}
|
|
print("✓ Info fetched");
|
|
if info.format != () { print(` format: ${info.format}`); }
|
|
if info["virtual-size"] != () { print(` virtual-size: ${info["virtual-size"]}`); }
|
|
|
|
print("\n--- Test 3: Snapshot create/list/delete (offline) ---");
|
|
let snap_name = "s1";
|
|
try {
|
|
qcow2_snapshot_create(img_path, snap_name);
|
|
} catch (err) {
|
|
print(`❌ snapshot_create failed: ${err}`);
|
|
exit();
|
|
}
|
|
print("✓ snapshot created: s1");
|
|
|
|
let snaps;
|
|
try {
|
|
snaps = qcow2_snapshot_list(img_path);
|
|
} catch (err) {
|
|
print(`❌ snapshot_list failed: ${err}`);
|
|
exit();
|
|
}
|
|
print(`✓ snapshot_list ok, count=${snaps.len()}`);
|
|
|
|
try {
|
|
qcow2_snapshot_delete(img_path, snap_name);
|
|
} catch (err) {
|
|
print(`❌ snapshot_delete failed: ${err}`);
|
|
exit();
|
|
}
|
|
print("✓ snapshot deleted: s1");
|
|
|
|
// Optional: Base image builder (commented to avoid big downloads by default)
|
|
// Uncomment to test manually on a dev machine with bandwidth.
|
|
// print("\n--- Optional: Build Ubuntu 24.04 Base ---");
|
|
// let base_dir = "/tmp/virt_images";
|
|
// let base = qcow2_build_ubuntu_24_04_base(base_dir, 10);
|
|
// if base.is_err() {
|
|
// print(`⚠️ base build failed or skipped: ${base.unwrap_err()}`);
|
|
// } else {
|
|
// let m = base.unwrap();
|
|
// print(`✓ Base image path: ${m.base_image_path}`);
|
|
// print(`✓ Base snapshot: ${m.snapshot}`);
|
|
// print(`✓ Source URL: ${m.url}`);
|
|
// if m.resized_to_gb != () { print(`✓ Resized to: ${m.resized_to_gb}G`); }
|
|
// }
|
|
|
|
print("\n=== QCOW2 Basic Tests Completed ==="); |