systemd-ts 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/dist/index-DeNBLyGA.d.mts +1612 -0
- package/dist/index.d.mts +2 -1612
- package/dist/index.mjs +1 -1609
- package/dist/main-BXq7TQdg.mjs +1610 -0
- package/dist/test.d.mts +29 -1
- package/dist/test.mjs +93 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -322,6 +322,67 @@ This lower-level flow is useful when you want exact control over
|
|
|
322
322
|
materialization, enablement, or startup behavior without going through the
|
|
323
323
|
code-owned upkeep layer.
|
|
324
324
|
|
|
325
|
+
## Testing Against A Real User Manager
|
|
326
|
+
|
|
327
|
+
The package also ships a `systemd-ts/test` module for integration tests that
|
|
328
|
+
need a real `systemd --user` environment.
|
|
329
|
+
|
|
330
|
+
Use `ensureTestHost()` to warm the test host, `createTestSandbox()` to create
|
|
331
|
+
an isolated unit directory, and `sandboxSystemd()` when you want a `Systemd`
|
|
332
|
+
instance already pointed at that sandbox.
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { afterEach, beforeAll, beforeEach, test } from "vite-plus/test";
|
|
336
|
+
|
|
337
|
+
import { SystemdService } from "systemd-ts";
|
|
338
|
+
import {
|
|
339
|
+
createTestSandbox,
|
|
340
|
+
destroyCurrentTestSandbox,
|
|
341
|
+
ensureTestHost,
|
|
342
|
+
sandboxSystemd,
|
|
343
|
+
useCurrentTestSandbox,
|
|
344
|
+
} from "systemd-ts/test";
|
|
345
|
+
|
|
346
|
+
beforeAll(async () => {
|
|
347
|
+
await ensureTestHost();
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
beforeEach(async (context) => {
|
|
351
|
+
await createTestSandbox(context.task.name);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
afterEach(async () => {
|
|
355
|
+
await destroyCurrentTestSandbox();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test(`starts a service in a sandbox`, async () => {
|
|
359
|
+
const sandbox = useCurrentTestSandbox();
|
|
360
|
+
const systemd = sandboxSystemd();
|
|
361
|
+
const markerFile = `${sandbox.workDir}/started.txt`;
|
|
362
|
+
const service = new SystemdService({
|
|
363
|
+
name: sandbox.namePrefix,
|
|
364
|
+
service: {
|
|
365
|
+
Type: `oneshot`,
|
|
366
|
+
ExecStart: `/usr/bin/bash -lc 'echo started > ${markerFile}'`,
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const materialized = await systemd.materialize(service);
|
|
371
|
+
if (!materialized.ok) {
|
|
372
|
+
throw materialized.error;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const started = await systemd.start(service);
|
|
376
|
+
if (!started.ok) {
|
|
377
|
+
throw started.error;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
If you need direct executor access for helpers outside `Systemd`, the same
|
|
383
|
+
module also exports `guestCommandExecutor`, `isolatedGuestCommandExecutor`, and
|
|
384
|
+
`createGuestCommandExecutor()`.
|
|
385
|
+
|
|
325
386
|
## Explore Further
|
|
326
387
|
|
|
327
388
|
The README is meant to answer what the library is for.
|