sal/net/tests/rhai/01_tcp_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

109 lines
2.6 KiB
Plaintext

// TCP Operations Test Suite
// Tests TCP connectivity functions through Rhai integration
print("=== TCP Operations Test Suite ===");
let test_count = 0;
let passed_count = 0;
// Test 1: TCP check on closed port
test_count += 1;
print(`\nTest ${test_count}: TCP check on closed port`);
let test1_result = tcp_check("127.0.0.1", 65534);
if !test1_result {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 2: TCP check on invalid host
test_count += 1;
print(`\nTest ${test_count}: TCP check on invalid host`);
let test2_result = tcp_check("nonexistent-host-12345.invalid", 80);
if !test2_result {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 3: TCP check with empty host
test_count += 1;
print(`\nTest ${test_count}: TCP check with empty host`);
let test3_result = tcp_check("", 80);
if !test3_result {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 4: TCP ping localhost
test_count += 1;
print(`\nTest ${test_count}: TCP ping localhost`);
let test4_result = tcp_ping("localhost");
if test4_result == true || test4_result == false {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 5: TCP ping invalid host
test_count += 1;
print(`\nTest ${test_count}: TCP ping invalid host`);
let test5_result = tcp_ping("nonexistent-host-12345.invalid");
if !test5_result {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 6: Multiple TCP checks
test_count += 1;
print(`\nTest ${test_count}: Multiple TCP checks`);
let ports = [65534, 65533, 65532];
let all_closed = true;
for port in ports {
let result = tcp_check("127.0.0.1", port);
if result {
all_closed = false;
break;
}
}
if all_closed {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Test 7: TCP operations consistency
test_count += 1;
print(`\nTest ${test_count}: TCP operations consistency`);
let result1 = tcp_check("127.0.0.1", 65534);
let result2 = tcp_check("127.0.0.1", 65534);
if result1 == result2 {
print(" ✓ PASSED");
passed_count += 1;
} else {
print(" ✗ FAILED");
}
// Summary
print("\n=== TCP 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 TCP tests passed!");
} else {
print("⚠️ Some TCP tests failed.");
}
// Return success if all tests passed
passed_count == test_count