mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:32:44 +00:00
refactor: register gateway service adapters
This commit is contained in:
40
src/daemon/service.test.ts
Normal file
40
src/daemon/service.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { resolveGatewayService } from "./service.js";
|
||||
|
||||
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, "platform");
|
||||
|
||||
function setPlatform(value: NodeJS.Platform | "aix") {
|
||||
if (!originalPlatformDescriptor) {
|
||||
throw new Error("missing process.platform descriptor");
|
||||
}
|
||||
Object.defineProperty(process, "platform", {
|
||||
configurable: true,
|
||||
enumerable: originalPlatformDescriptor.enumerable ?? false,
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (!originalPlatformDescriptor) {
|
||||
return;
|
||||
}
|
||||
Object.defineProperty(process, "platform", originalPlatformDescriptor);
|
||||
});
|
||||
|
||||
describe("resolveGatewayService", () => {
|
||||
it.each([
|
||||
{ platform: "darwin" as const, label: "LaunchAgent", loadedText: "loaded" },
|
||||
{ platform: "linux" as const, label: "systemd", loadedText: "enabled" },
|
||||
{ platform: "win32" as const, label: "Scheduled Task", loadedText: "registered" },
|
||||
])("returns the registered adapter for $platform", ({ platform, label, loadedText }) => {
|
||||
setPlatform(platform);
|
||||
const service = resolveGatewayService();
|
||||
expect(service.label).toBe(label);
|
||||
expect(service.loadedText).toBe(loadedText);
|
||||
});
|
||||
|
||||
it("throws for unsupported platforms", () => {
|
||||
setPlatform("aix");
|
||||
expect(() => resolveGatewayService()).toThrow("Gateway service install not supported on aix");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user