fixed test script errors
This commit is contained in:
		| @@ -33,9 +33,11 @@ pub fn run(script_path: &str) -> Result<(), Box<dyn Error>> { | ||||
|     // TODO: if we create a scope here we could clean up all the different functionsand types regsitered wit the engine | ||||
|     // We should generalize the way we add things to the scope for each module sepeartely | ||||
|     let mut scope = Scope::new(); | ||||
|     // TODO: this should be done for the other clients as well (but not here of course, in each module) | ||||
|     let hetzner_client = sal::hetzner::api::Client::new(sal::hetzner::config::Config::from_env().unwrap()); | ||||
|     scope.push("hetzner", hetzner_client); | ||||
|     // Conditionally add Hetzner client only when env config is present | ||||
|     if let Ok(cfg) = sal::hetzner::config::Config::from_env() { | ||||
|         let hetzner_client = sal::hetzner::api::Client::new(cfg); | ||||
|         scope.push("hetzner", hetzner_client); | ||||
|     } | ||||
|     // This makes it easy to call e.g. `hetzner.get_server()` or `mycelium.get_connected_peers()` | ||||
|     // --> without the need of manually created a client for each one first | ||||
|     // --> could be conditionally compiled to only use those who we need (we only push the things to the scope that we actually need to run the script) | ||||
|   | ||||
| @@ -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"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user