Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add the `mycelium` package to the workspace members. - Add `sal-mycelium` dependency to `Cargo.toml`. - Update MONOREPO_CONVERSION_PLAN.md to reflect the addition and completion of the mycelium package.
175 lines
5.1 KiB
Plaintext
175 lines
5.1 KiB
Plaintext
// Mycelium Rhai Test Runner
|
|
//
|
|
// This script runs all Mycelium-related Rhai tests and reports results.
|
|
// It includes simplified versions of the individual tests to avoid dependency issues.
|
|
|
|
print("=== Mycelium Rhai Test Suite ===");
|
|
print("Running comprehensive tests for Mycelium Rhai integration...\n");
|
|
|
|
let total_tests = 0;
|
|
let passed_tests = 0;
|
|
let failed_tests = 0;
|
|
let skipped_tests = 0;
|
|
|
|
// Test 1: Function Registration
|
|
print("Test 1: Function Registration");
|
|
total_tests += 1;
|
|
try {
|
|
// Test that all mycelium functions are registered
|
|
let invalid_url = "http://localhost:99999";
|
|
let all_functions_exist = true;
|
|
|
|
try { mycelium_get_node_info(invalid_url); } catch(err) {
|
|
if !err.to_string().contains("Mycelium error") { all_functions_exist = false; }
|
|
}
|
|
|
|
try { mycelium_list_peers(invalid_url); } catch(err) {
|
|
if !err.to_string().contains("Mycelium error") { all_functions_exist = false; }
|
|
}
|
|
|
|
try { mycelium_send_message(invalid_url, "dest", "topic", "msg", -1); } catch(err) {
|
|
if !err.to_string().contains("Mycelium error") { all_functions_exist = false; }
|
|
}
|
|
|
|
if all_functions_exist {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: All mycelium functions are registered");
|
|
} else {
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Some mycelium functions are missing");
|
|
}
|
|
} catch(err) {
|
|
failed_tests += 1;
|
|
print(`✗ ERROR: Function registration test failed - ${err}`);
|
|
}
|
|
|
|
// Test 2: Error Handling
|
|
print("\nTest 2: Error Handling");
|
|
total_tests += 1;
|
|
try {
|
|
mycelium_get_node_info("http://localhost:99999");
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Should have failed with connection error");
|
|
} catch(err) {
|
|
if err.to_string().contains("Mycelium error") {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: Error handling works correctly");
|
|
} else {
|
|
failed_tests += 1;
|
|
print(`✗ FAILED: Unexpected error format - ${err}`);
|
|
}
|
|
}
|
|
|
|
// Test 3: Parameter Validation
|
|
print("\nTest 3: Parameter Validation");
|
|
total_tests += 1;
|
|
try {
|
|
mycelium_get_node_info("");
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Should have failed with empty API URL");
|
|
} catch(err) {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: Parameter validation works correctly");
|
|
}
|
|
|
|
// Test 4: Timeout Parameter Handling
|
|
print("\nTest 4: Timeout Parameter Handling");
|
|
total_tests += 1;
|
|
try {
|
|
let invalid_url = "http://localhost:99999";
|
|
|
|
// Test negative timeout (should be treated as no timeout)
|
|
try {
|
|
mycelium_receive_messages(invalid_url, "topic", -1);
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Should have failed with connection error");
|
|
} catch(err) {
|
|
if err.to_string().contains("Mycelium error") {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: Timeout parameter handling works correctly");
|
|
} else {
|
|
failed_tests += 1;
|
|
print(`✗ FAILED: Unexpected error - ${err}`);
|
|
}
|
|
}
|
|
} catch(err) {
|
|
failed_tests += 1;
|
|
print(`✗ ERROR: Timeout test failed - ${err}`);
|
|
}
|
|
|
|
// Check if Mycelium is available for integration tests
|
|
let test_api_url = "http://localhost:8989";
|
|
let fallback_api_url = "http://localhost:7777";
|
|
let available_api_url = "";
|
|
|
|
try {
|
|
mycelium_get_node_info(test_api_url);
|
|
available_api_url = test_api_url;
|
|
} catch(err) {
|
|
try {
|
|
mycelium_get_node_info(fallback_api_url);
|
|
available_api_url = fallback_api_url;
|
|
} catch(err2) {
|
|
// No Mycelium node available
|
|
}
|
|
}
|
|
|
|
if available_api_url != "" {
|
|
print(`\n✓ Mycelium node available at: ${available_api_url}`);
|
|
|
|
// Test 5: Get Node Info
|
|
print("\nTest 5: Get Node Info");
|
|
total_tests += 1;
|
|
try {
|
|
let node_info = mycelium_get_node_info(available_api_url);
|
|
|
|
if type_of(node_info) == "map" {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: Node info retrieved successfully");
|
|
} else {
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Node info should be an object");
|
|
}
|
|
} catch(err) {
|
|
failed_tests += 1;
|
|
print(`✗ ERROR: Node info test failed - ${err}`);
|
|
}
|
|
|
|
// Test 6: List Peers
|
|
print("\nTest 6: List Peers");
|
|
total_tests += 1;
|
|
try {
|
|
let peers = mycelium_list_peers(available_api_url);
|
|
|
|
if type_of(peers) == "array" {
|
|
passed_tests += 1;
|
|
print("✓ PASSED: Peers listed successfully");
|
|
} else {
|
|
failed_tests += 1;
|
|
print("✗ FAILED: Peers should be an array");
|
|
}
|
|
} catch(err) {
|
|
failed_tests += 1;
|
|
print(`✗ ERROR: List peers test failed - ${err}`);
|
|
}
|
|
} else {
|
|
print("\n⚠ No Mycelium node available - skipping integration tests");
|
|
skipped_tests += 2; // Skip node info and list peers tests
|
|
total_tests += 2;
|
|
}
|
|
|
|
// Print final results
|
|
print("\n=== Test Results ===");
|
|
print(`Total Tests: ${total_tests}`);
|
|
print(`Passed: ${passed_tests}`);
|
|
print(`Failed: ${failed_tests}`);
|
|
print(`Skipped: ${skipped_tests}`);
|
|
|
|
if failed_tests == 0 {
|
|
print("\n✓ All tests passed!");
|
|
} else {
|
|
print(`\n✗ ${failed_tests} test(s) failed.`);
|
|
}
|
|
|
|
print("\n=== Mycelium Rhai Test Suite Completed ===");
|