sal/rhaiexamples/nerdctl_test.rhai
2025-04-04 21:51:31 +02:00

66 lines
1.9 KiB
Plaintext

// nerdctl_test.rhai
// Tests the nerdctl wrapper functionality without requiring a running containerd daemon
// Check if nerdctl is installed
let nerdctl_exists = which("nerdctl");
println(`Nerdctl exists: ${nerdctl_exists}`);
// Test creating run options
println("\nTesting run options creation:");
let run_options = new_run_options();
println(`Default run options created: ${run_options}`);
println(`- name: ${run_options.name}`);
println(`- detach: ${run_options.detach}`);
println(`- ports: ${run_options.ports}`);
println(`- snapshotter: ${run_options.snapshotter}`);
// Modify run options
println("\nModifying run options:");
run_options.name = "test-container";
run_options.detach = false;
run_options.ports = ["8080:80", "8443:443"];
run_options.snapshotter = "overlayfs";
println(`Modified run options: ${run_options}`);
println(`- name: ${run_options.name}`);
println(`- detach: ${run_options.detach}`);
println(`- ports: ${run_options.ports}`);
println(`- snapshotter: ${run_options.snapshotter}`);
// Test function availability
println("\nTesting function availability:");
let functions = [
"nerdctl_run",
"nerdctl_run_with_name",
"nerdctl_run_with_port",
"nerdctl_exec",
"nerdctl_copy",
"nerdctl_stop",
"nerdctl_remove",
"nerdctl_list",
"nerdctl_images",
"nerdctl_image_remove",
"nerdctl_image_push",
"nerdctl_image_tag",
"nerdctl_image_pull",
"nerdctl_image_commit",
"nerdctl_image_build"
];
// Try to access each function (this will throw an error if the function doesn't exist)
for func in functions {
let exists = is_function_registered(func);
println(`Function ${func} registered: ${exists}`);
}
// Helper function to check if a function is registered
fn is_function_registered(name) {
try {
// This will throw an error if the function doesn't exist
eval(`${name}`);
return true;
} catch {
return false;
}
}
"Nerdctl wrapper test completed successfully!"