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.
150 lines
4.2 KiB
Plaintext
150 lines
4.2 KiB
Plaintext
// Service lifecycle management test script
|
|
// This script tests creating, managing, and deleting services
|
|
|
|
// 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. Skipping tests.");
|
|
return;
|
|
}
|
|
|
|
print("=== Service Lifecycle Test ===");
|
|
|
|
let service_name = "rhai-lifecycle-test";
|
|
let exec_command = "echo 'Hello from Rhai lifecycle test'";
|
|
let oneshot = true;
|
|
|
|
// Clean up any existing service first
|
|
print("\n0. Cleaning up any existing test service...");
|
|
try {
|
|
zinit_stop(socket_path, service_name);
|
|
zinit_forget(socket_path, service_name);
|
|
zinit_delete_service(socket_path, service_name);
|
|
print("✓ Cleanup completed");
|
|
} catch(e) {
|
|
print(" (Cleanup errors are expected if service doesn't exist)");
|
|
}
|
|
|
|
// Test 1: Service creation
|
|
print("\n1. Testing service creation...");
|
|
try {
|
|
let create_result = zinit_create_service(socket_path, service_name, exec_command, oneshot);
|
|
print(`✓ Service created: ${create_result}`);
|
|
} catch(e) {
|
|
print(`✗ Service creation failed: ${e}`);
|
|
print("⚠ Remaining tests will be skipped");
|
|
return;
|
|
}
|
|
|
|
// Test 2: Service monitoring
|
|
print("\n2. Testing service monitoring...");
|
|
try {
|
|
let monitor_result = zinit_monitor(socket_path, service_name);
|
|
print(`✓ Service monitoring started: ${monitor_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Service monitoring failed: ${e}`);
|
|
}
|
|
|
|
// Test 3: Service start
|
|
print("\n3. Testing service start...");
|
|
try {
|
|
let start_result = zinit_start(socket_path, service_name);
|
|
print(`✓ Service started: ${start_result}`);
|
|
|
|
// Wait a moment for the service to run
|
|
print(" Waiting for service to execute...");
|
|
// Note: Rhai doesn't have sleep, so we'll just continue
|
|
|
|
} catch(e) {
|
|
print(`⚠ Service start failed: ${e}`);
|
|
}
|
|
|
|
// Test 4: Service status check
|
|
print("\n4. Testing service status...");
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(`✓ Service status retrieved:`);
|
|
print(` Name: ${status.name}`);
|
|
print(` PID: ${status.pid}`);
|
|
print(` State: ${status.state}`);
|
|
print(` Target: ${status.target}`);
|
|
} catch(e) {
|
|
print(`⚠ Service status check failed: ${e}`);
|
|
}
|
|
|
|
// Test 5: Service configuration retrieval
|
|
print("\n5. Testing service configuration retrieval...");
|
|
try {
|
|
let config = zinit_get_service(socket_path, service_name);
|
|
print(`✓ Service configuration retrieved: ${type_of(config)}`);
|
|
print(` Config: ${config}`);
|
|
} catch(e) {
|
|
print(`⚠ Service configuration retrieval failed: ${e}`);
|
|
}
|
|
|
|
// Test 6: Service restart
|
|
print("\n6. Testing service restart...");
|
|
try {
|
|
let restart_result = zinit_restart(socket_path, service_name);
|
|
print(`✓ Service restarted: ${restart_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Service restart failed: ${e}`);
|
|
}
|
|
|
|
// Test 7: Service stop
|
|
print("\n7. Testing service stop...");
|
|
try {
|
|
let stop_result = zinit_stop(socket_path, service_name);
|
|
print(`✓ Service stopped: ${stop_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Service stop failed: ${e}`);
|
|
}
|
|
|
|
// Test 8: Service forget (stop monitoring)
|
|
print("\n8. Testing service forget...");
|
|
try {
|
|
let forget_result = zinit_forget(socket_path, service_name);
|
|
print(`✓ Service forgotten: ${forget_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Service forget failed: ${e}`);
|
|
}
|
|
|
|
// Test 9: Service deletion
|
|
print("\n9. Testing service deletion...");
|
|
try {
|
|
let delete_result = zinit_delete_service(socket_path, service_name);
|
|
print(`✓ Service deleted: ${delete_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Service deletion failed: ${e}`);
|
|
}
|
|
|
|
// Test 10: Verify service is gone
|
|
print("\n10. Verifying service deletion...");
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(`⚠ Service still exists after deletion: ${status}`);
|
|
} catch(e) {
|
|
print(`✓ Service correctly removed: ${e}`);
|
|
}
|
|
|
|
print("\n=== Service Lifecycle Test Complete ===");
|