sal/net/tests/rhai/03_ssh_operations.rhai
Mahmoud-Emad 74217364fa
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
feat: Add sal-net package to workspace
- Add new sal-net package to the workspace.
- Update MONOREPO_CONVERSION_PLAN.md to reflect the
  addition of the sal-net package and mark it as
  production-ready.
- Add Cargo.toml and README.md for the sal-net package.
2025-06-22 09:52:20 +03:00

111 lines
3.6 KiB
Plaintext

// SSH Operations Test Suite
// Tests SSH connectivity functions through Rhai integration
print("=== SSH Operations Test Suite ===");
let test_count = 0;
let passed_count = 0;
// Test 1: SSH execute with invalid host
test_count += 1;
print(`\nTest ${test_count}: SSH execute with invalid host`);
let exit_code = ssh_execute("nonexistent-host-12345.invalid", "testuser", "echo test");
if exit_code != 0 {
print(" ✓ PASSED - SSH correctly failed for invalid host");
passed_count += 1;
} else {
print(" ✗ FAILED - SSH should fail for invalid host");
}
// Test 2: SSH execute output with invalid host
test_count += 1;
print(`\nTest ${test_count}: SSH execute output with invalid host`);
let output = ssh_execute_output("nonexistent-host-12345.invalid", "testuser", "echo test");
// Output can be empty or contain error message, both are valid
print(" ✓ PASSED - SSH execute output function works");
passed_count += 1;
// Test 3: SSH ping to invalid host
test_count += 1;
print(`\nTest ${test_count}: SSH ping to invalid host`);
let result = ssh_ping("nonexistent-host-12345.invalid", "testuser");
if !result {
print(" ✓ PASSED - SSH ping correctly failed for invalid host");
passed_count += 1;
} else {
print(" ✗ FAILED - SSH ping should fail for invalid host");
}
// Test 4: SSH ping to localhost (may work or fail depending on SSH setup)
test_count += 1;
print(`\nTest ${test_count}: SSH ping to localhost`);
let localhost_result = ssh_ping("localhost", "testuser");
if localhost_result == true || localhost_result == false {
print(" ✓ PASSED - SSH ping function works (result depends on SSH setup)");
passed_count += 1;
} else {
print(" ✗ FAILED - SSH ping should return boolean");
}
// Test 5: SSH execute with different commands
test_count += 1;
print(`\nTest ${test_count}: SSH execute with different commands`);
let echo_result = ssh_execute("invalid-host", "user", "echo hello");
let ls_result = ssh_execute("invalid-host", "user", "ls -la");
let whoami_result = ssh_execute("invalid-host", "user", "whoami");
if echo_result != 0 && ls_result != 0 && whoami_result != 0 {
print(" ✓ PASSED - All SSH commands correctly failed for invalid host");
passed_count += 1;
} else {
print(" ✗ FAILED - SSH commands should fail for invalid host");
}
// Test 6: SSH error handling with malformed inputs
test_count += 1;
print(`\nTest ${test_count}: SSH error handling with malformed inputs`);
let malformed_hosts = ["..invalid..", "host..name", ""];
let all_failed = true;
for host in malformed_hosts {
let result = ssh_ping(host, "testuser");
if result {
all_failed = false;
break;
}
}
if all_failed {
print(" ✓ PASSED - All malformed hosts correctly failed");
passed_count += 1;
} else {
print(" ✗ FAILED - Malformed hosts should fail");
}
// Test 7: SSH function consistency
test_count += 1;
print(`\nTest ${test_count}: SSH function consistency`);
let result1 = ssh_execute("invalid-host", "user", "echo test");
let result2 = ssh_execute("invalid-host", "user", "echo test");
if result1 == result2 {
print(" ✓ PASSED - SSH functions are consistent");
passed_count += 1;
} else {
print(" ✗ FAILED - SSH functions should be consistent");
}
// Summary
print("\n=== SSH Operations Test Results ===");
print(`Total tests: ${test_count}`);
print(`Passed: ${passed_count}`);
print(`Failed: ${test_count - passed_count}`);
if passed_count == test_count {
print("🎉 All SSH tests passed!");
} else {
print("⚠️ Some SSH tests failed.");
}
// Return success if all tests passed
passed_count == test_count