fixed test script errors

This commit is contained in:
Maxime Van Hees
2025-08-20 15:42:12 +02:00
parent 169c62da47
commit d1c80863b8
2 changed files with 33 additions and 30 deletions

View File

@@ -11,55 +11,56 @@ if qemu == () {
exit();
}
// Helper: unique temp path
let now = 0;
try {
// if process module exists you could pull a timestamp; fallback to random-ish suffix
now = 100000 + (rand() % 100000);
} catch (err) {
now = 100000 + (rand() % 100000);
}
let img_path = `/tmp/qcow2_test_${now}.img`;
// 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 ---");
let create_res = qcow2_create(img_path, 1);
if create_res.is_err() {
print(`❌ Create failed: ${create_res.unwrap_err()}`);
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(`✓ Created qcow2: ${img_path}`);
print("\n--- Test 2: Info ---");
let info_res = qcow2_info(img_path);
if info_res.is_err() {
print(`❌ Info failed: ${info_res.unwrap_err()}`);
let info;
try {
info = qcow2_info(img_path);
} catch (err) {
print(`❌ Info failed: ${err}`);
exit();
}
let info = info_res.unwrap();
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";
let screate = qcow2_snapshot_create(img_path, snap_name);
if screate.is_err() {
print(`❌ snapshot_create failed: ${screate.unwrap_err()}`);
try {
qcow2_snapshot_create(img_path, snap_name);
} catch (err) {
print(`❌ snapshot_create failed: ${err}`);
exit();
}
print("✓ snapshot created: s1");
let slist = qcow2_snapshot_list(img_path);
if slist.is_err() {
print(`❌ snapshot_list failed: ${slist.unwrap_err()}`);
let snaps;
try {
snaps = qcow2_snapshot_list(img_path);
} catch (err) {
print(`❌ snapshot_list failed: ${err}`);
exit();
}
let snaps = slist.unwrap();
print(`✓ snapshot_list ok, count=${snaps.len()}`);
let sdel = qcow2_snapshot_delete(img_path, snap_name);
if sdel.is_err() {
print(`❌ snapshot_delete failed: ${sdel.unwrap_err()}`);
try {
qcow2_snapshot_delete(img_path, snap_name);
} catch (err) {
print(`❌ snapshot_delete failed: ${err}`);
exit();
}
print("✓ snapshot deleted: s1");