feat: Add zinit_client package to workspace
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add `zinit_client` package to the workspace, enabling its use in the SAL monorepo. This allows for better organization and dependency management. - Update `MONOREPO_CONVERSION_PLAN.md` to reflect the addition of `zinit_client` and its status. This ensures the conversion plan stays up-to-date. - Move `src/zinit_client/` directory to `zinit_client/` for better organization. This improves the overall structure of the project. - Update references to `zinit_client` to use the new path. This ensures the codebase correctly links to the `zinit_client` package.
This commit is contained in:
290
zinit_client/tests/rhai/run_all_tests.rhai
Normal file
290
zinit_client/tests/rhai/run_all_tests.rhai
Normal file
@@ -0,0 +1,290 @@
|
||||
// Zinit Client Rhai Test Runner
|
||||
// This script runs all zinit client Rhai tests
|
||||
|
||||
print("=== Zinit Client Rhai Test Suite ===");
|
||||
print("Running comprehensive tests for sal-zinit-client Rhai integration");
|
||||
print("");
|
||||
|
||||
// Configuration
|
||||
let socket_paths = [
|
||||
"/var/run/zinit.sock",
|
||||
"/tmp/zinit.sock",
|
||||
"/run/zinit.sock",
|
||||
"./zinit.sock"
|
||||
];
|
||||
|
||||
// Find available socket
|
||||
let socket_path = "";
|
||||
for path in socket_paths {
|
||||
try {
|
||||
let test_services = zinit_list(path);
|
||||
socket_path = path;
|
||||
print(`✓ Found working Zinit socket at: ${path}`);
|
||||
break;
|
||||
} catch(e) {
|
||||
// Continue to next path
|
||||
}
|
||||
}
|
||||
|
||||
if socket_path == "" {
|
||||
print("⚠ No working Zinit socket found.");
|
||||
print(" Please ensure Zinit is running and accessible at one of these paths:");
|
||||
for path in socket_paths {
|
||||
print(` ${path}`);
|
||||
}
|
||||
print("");
|
||||
print(" To start Zinit for testing:");
|
||||
print(" sudo zinit --socket /tmp/zinit.sock");
|
||||
print("");
|
||||
print("⚠ All tests will be skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
print("");
|
||||
print("=== Test Environment Information ===");
|
||||
try {
|
||||
let services = zinit_list(socket_path);
|
||||
print(`Current services managed by Zinit: ${services.len()}`);
|
||||
|
||||
if services.len() > 0 {
|
||||
print("Existing services:");
|
||||
for name in services.keys() {
|
||||
let state = services[name];
|
||||
print(` ${name}: ${state}`);
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
print(`Error getting service list: ${e}`);
|
||||
}
|
||||
|
||||
print("");
|
||||
print("=== Running Test Suite ===");
|
||||
|
||||
// Test results tracking
|
||||
let test_results = #{};
|
||||
let total_tests = 0;
|
||||
let passed_tests = 0;
|
||||
let failed_tests = 0;
|
||||
|
||||
// Test 1: Basic Operations
|
||||
print("\n--- Test 1: Basic Operations ---");
|
||||
total_tests += 1;
|
||||
try {
|
||||
// Test basic listing
|
||||
let services = zinit_list(socket_path);
|
||||
print(`✓ Service listing: ${services.len()} services`);
|
||||
|
||||
// Test logs
|
||||
let logs = zinit_logs_all(socket_path);
|
||||
print(`✓ Log retrieval: ${logs.len()} entries`);
|
||||
|
||||
// Test filtered logs
|
||||
let filtered_logs = zinit_logs(socket_path, "zinit");
|
||||
print(`✓ Filtered logs: ${filtered_logs.len()} entries`);
|
||||
|
||||
test_results.basic_operations = "PASSED";
|
||||
passed_tests += 1;
|
||||
print("✓ Basic Operations: PASSED");
|
||||
|
||||
} catch(e) {
|
||||
test_results.basic_operations = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print(`✗ Basic Operations: FAILED - ${e}`);
|
||||
}
|
||||
|
||||
// Test 2: Service Creation and Management
|
||||
print("\n--- Test 2: Service Creation and Management ---");
|
||||
total_tests += 1;
|
||||
let test_service = "rhai-test-runner-service";
|
||||
try {
|
||||
// Clean up first
|
||||
try {
|
||||
zinit_stop(socket_path, test_service);
|
||||
zinit_forget(socket_path, test_service);
|
||||
zinit_delete_service(socket_path, test_service);
|
||||
} catch(e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
// Create service
|
||||
let create_result = zinit_create_service(socket_path, test_service, "echo 'Test service'", true);
|
||||
print(`✓ Service creation: ${create_result}`);
|
||||
|
||||
// Monitor service
|
||||
let monitor_result = zinit_monitor(socket_path, test_service);
|
||||
print(`✓ Service monitoring: ${monitor_result}`);
|
||||
|
||||
// Start service
|
||||
let start_result = zinit_start(socket_path, test_service);
|
||||
print(`✓ Service start: ${start_result}`);
|
||||
|
||||
// Get status
|
||||
let status = zinit_status(socket_path, test_service);
|
||||
print(`✓ Service status: ${status.state}`);
|
||||
|
||||
// Stop service
|
||||
let stop_result = zinit_stop(socket_path, test_service);
|
||||
print(`✓ Service stop: ${stop_result}`);
|
||||
|
||||
// Forget service
|
||||
let forget_result = zinit_forget(socket_path, test_service);
|
||||
print(`✓ Service forget: ${forget_result}`);
|
||||
|
||||
// Delete service
|
||||
let delete_result = zinit_delete_service(socket_path, test_service);
|
||||
print(`✓ Service deletion: ${delete_result}`);
|
||||
|
||||
test_results.service_management = "PASSED";
|
||||
passed_tests += 1;
|
||||
print("✓ Service Management: PASSED");
|
||||
|
||||
} catch(e) {
|
||||
test_results.service_management = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print(`✗ Service Management: FAILED - ${e}`);
|
||||
|
||||
// Cleanup on failure
|
||||
try {
|
||||
zinit_stop(socket_path, test_service);
|
||||
zinit_forget(socket_path, test_service);
|
||||
zinit_delete_service(socket_path, test_service);
|
||||
} catch(cleanup_e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
}
|
||||
|
||||
// Test 3: Signal Handling
|
||||
print("\n--- Test 3: Signal Handling ---");
|
||||
total_tests += 1;
|
||||
let signal_service = "rhai-signal-test-service";
|
||||
try {
|
||||
// Clean up first
|
||||
try {
|
||||
zinit_stop(socket_path, signal_service);
|
||||
zinit_forget(socket_path, signal_service);
|
||||
zinit_delete_service(socket_path, signal_service);
|
||||
} catch(e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
// Create long-running service
|
||||
let create_result = zinit_create_service(socket_path, signal_service, "sleep 10", false);
|
||||
print(`✓ Signal test service created: ${create_result}`);
|
||||
|
||||
// Start service
|
||||
zinit_monitor(socket_path, signal_service);
|
||||
let start_result = zinit_start(socket_path, signal_service);
|
||||
print(`✓ Signal test service started: ${start_result}`);
|
||||
|
||||
// Send TERM signal
|
||||
let kill_result = zinit_kill(socket_path, signal_service, "TERM");
|
||||
print(`✓ TERM signal sent: ${kill_result}`);
|
||||
|
||||
// Check status after signal
|
||||
try {
|
||||
let status = zinit_status(socket_path, signal_service);
|
||||
print(`✓ Status after signal: ${status.state}`);
|
||||
} catch(e) {
|
||||
print(` Status check: ${e}`);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
zinit_stop(socket_path, signal_service);
|
||||
zinit_forget(socket_path, signal_service);
|
||||
zinit_delete_service(socket_path, signal_service);
|
||||
|
||||
test_results.signal_handling = "PASSED";
|
||||
passed_tests += 1;
|
||||
print("✓ Signal Handling: PASSED");
|
||||
|
||||
} catch(e) {
|
||||
test_results.signal_handling = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print(`✗ Signal Handling: FAILED - ${e}`);
|
||||
|
||||
// Cleanup on failure
|
||||
try {
|
||||
zinit_stop(socket_path, signal_service);
|
||||
zinit_forget(socket_path, signal_service);
|
||||
zinit_delete_service(socket_path, signal_service);
|
||||
} catch(cleanup_e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
}
|
||||
|
||||
// Test 4: Error Handling
|
||||
print("\n--- Test 4: Error Handling ---");
|
||||
total_tests += 1;
|
||||
try {
|
||||
// Test with non-existent service
|
||||
try {
|
||||
let status = zinit_status(socket_path, "non-existent-service-12345");
|
||||
print("⚠ Unexpected success for non-existent service");
|
||||
test_results.error_handling = "FAILED: Should have failed for non-existent service";
|
||||
failed_tests += 1;
|
||||
} catch(e) {
|
||||
print(`✓ Correctly failed for non-existent service: ${e}`);
|
||||
test_results.error_handling = "PASSED";
|
||||
passed_tests += 1;
|
||||
print("✓ Error Handling: PASSED");
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
test_results.error_handling = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print(`✗ Error Handling: FAILED - ${e}`);
|
||||
}
|
||||
|
||||
// Test 5: Configuration Retrieval
|
||||
print("\n--- Test 5: Configuration Retrieval ---");
|
||||
total_tests += 1;
|
||||
try {
|
||||
let services = zinit_list(socket_path);
|
||||
if services.len() > 0 {
|
||||
let service_names = services.keys();
|
||||
let first_service = service_names[0];
|
||||
|
||||
try {
|
||||
let config = zinit_get_service(socket_path, first_service);
|
||||
print(`✓ Configuration retrieved for '${first_service}': ${type_of(config)}`);
|
||||
test_results.config_retrieval = "PASSED";
|
||||
passed_tests += 1;
|
||||
print("✓ Configuration Retrieval: PASSED");
|
||||
} catch(e) {
|
||||
print(`⚠ Configuration retrieval failed: ${e}`);
|
||||
test_results.config_retrieval = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print("✗ Configuration Retrieval: FAILED");
|
||||
}
|
||||
} else {
|
||||
print("⚠ No services available for configuration test");
|
||||
test_results.config_retrieval = "SKIPPED: No services available";
|
||||
print("⚠ Configuration Retrieval: SKIPPED");
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
test_results.config_retrieval = `FAILED: ${e}`;
|
||||
failed_tests += 1;
|
||||
print(`✗ Configuration Retrieval: FAILED - ${e}`);
|
||||
}
|
||||
|
||||
// Test Summary
|
||||
print("\n=== Test Summary ===");
|
||||
print(`Total tests: ${total_tests}`);
|
||||
print(`Passed: ${passed_tests}`);
|
||||
print(`Failed: ${failed_tests}`);
|
||||
print(`Success rate: ${(passed_tests * 100 / total_tests).round()}%`);
|
||||
|
||||
print("\nDetailed Results:");
|
||||
for test_name in test_results.keys() {
|
||||
let result = test_results[test_name];
|
||||
print(` ${test_name}: ${result}`);
|
||||
}
|
||||
|
||||
if failed_tests == 0 {
|
||||
print("\n🎉 All tests passed! Zinit client Rhai integration is working correctly.");
|
||||
} else {
|
||||
print(`\n⚠ ${failed_tests} test(s) failed. Please check the errors above.`);
|
||||
}
|
||||
|
||||
print("\n=== Zinit Client Rhai Test Suite Complete ===");
|
Reference in New Issue
Block a user