...
This commit is contained in:
53
packages/system/os/tests/rhai/02_download_operations.rhai
Normal file
53
packages/system/os/tests/rhai/02_download_operations.rhai
Normal file
@@ -0,0 +1,53 @@
|
||||
// 02_download_operations.rhai
|
||||
// Tests for download operations in the OS module
|
||||
|
||||
// Custom assert function
|
||||
fn assert_true(condition, message) {
|
||||
if !condition {
|
||||
print(`ASSERTION FAILED: ${message}`);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a test directory
|
||||
let test_dir = "rhai_test_download";
|
||||
mkdir(test_dir);
|
||||
print(`Created test directory: ${test_dir}`);
|
||||
|
||||
// Test which function to ensure curl is available
|
||||
let curl_path = which("curl");
|
||||
if curl_path == "" {
|
||||
print("Warning: curl not found, download tests may fail");
|
||||
} else {
|
||||
print(`✓ which: curl found at ${curl_path}`);
|
||||
}
|
||||
|
||||
// Test cmd_ensure_exists function
|
||||
let ensure_result = cmd_ensure_exists("curl");
|
||||
print(`✓ cmd_ensure_exists: ${ensure_result}`);
|
||||
|
||||
// Test download function with a small file
|
||||
let download_url = "https://raw.githubusercontent.com/rust-lang/rust/master/LICENSE-MIT";
|
||||
let download_dest = test_dir + "/license.txt";
|
||||
let min_size_kb = 1; // Minimum size in KB
|
||||
|
||||
print(`Downloading ${download_url}...`);
|
||||
let download_result = download_file(download_url, download_dest, min_size_kb);
|
||||
assert_true(exist(download_dest), "Download failed");
|
||||
print(`✓ download_file: ${download_result}`);
|
||||
|
||||
// Verify the downloaded file
|
||||
let file_content = file_read(download_dest);
|
||||
assert_true(file_content.contains("Permission is hereby granted"), "Downloaded file content is incorrect");
|
||||
print("✓ Downloaded file content verified");
|
||||
|
||||
// Test chmod_exec function
|
||||
let chmod_result = chmod_exec(download_dest);
|
||||
print(`✓ chmod_exec: ${chmod_result}`);
|
||||
|
||||
// Clean up
|
||||
delete(test_dir);
|
||||
assert_true(!exist(test_dir), "Directory deletion failed");
|
||||
print(`✓ Cleanup: Directory ${test_dir} removed`);
|
||||
|
||||
print("All download tests completed successfully!");
|
Reference in New Issue
Block a user