fix: harden onboarding for non-systemd environments
This commit is contained in:
35
src/daemon/systemd-availability.test.ts
Normal file
35
src/daemon/systemd-availability.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const execFileMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("node:child_process", () => ({
|
||||
execFile: execFileMock,
|
||||
}));
|
||||
|
||||
import { isSystemdUserServiceAvailable } from "./systemd.js";
|
||||
|
||||
describe("systemd availability", () => {
|
||||
beforeEach(() => {
|
||||
execFileMock.mockReset();
|
||||
});
|
||||
|
||||
it("returns true when systemctl --user succeeds", async () => {
|
||||
execFileMock.mockImplementation((_cmd, _args, _opts, cb) => {
|
||||
cb(null, "", "");
|
||||
});
|
||||
await expect(isSystemdUserServiceAvailable()).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it("returns false when systemd user bus is unavailable", async () => {
|
||||
execFileMock.mockImplementation((_cmd, _args, _opts, cb) => {
|
||||
const err = new Error("Failed to connect to bus") as Error & {
|
||||
stderr?: string;
|
||||
code?: number;
|
||||
};
|
||||
err.stderr = "Failed to connect to bus";
|
||||
err.code = 1;
|
||||
cb(err, "", "");
|
||||
});
|
||||
await expect(isSystemdUserServiceAvailable()).resolves.toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user