|
| 1 | +import type { ServiceInstance } from '../src/types' |
| 2 | +import { describe, expect, it } from 'bun:test' |
| 3 | +import { generateLaunchdPlist } from '../src/services/platform' |
| 4 | + |
| 5 | +function makeServiceInstance(name: string, overrides: Partial<ServiceInstance> = {}): ServiceInstance { |
| 6 | + return { |
| 7 | + name, |
| 8 | + status: 'stopped', |
| 9 | + enabled: false, |
| 10 | + definition: { |
| 11 | + name, |
| 12 | + displayName: name, |
| 13 | + packageDomain: 'example.org', |
| 14 | + executable: 'dummy', |
| 15 | + args: [], |
| 16 | + dataDirectory: '/tmp', |
| 17 | + pidFile: '/tmp/d.pid', |
| 18 | + port: 1234, |
| 19 | + dependencies: [], |
| 20 | + healthCheck: { command: ['true'], expectedExitCode: 0, timeout: 1, interval: 1, retries: 1 }, |
| 21 | + }, |
| 22 | + ...overrides, |
| 23 | + } as unknown as ServiceInstance |
| 24 | +} |
| 25 | + |
| 26 | +describe('services.shouldAutoStart → launchd RunAtLoad', () => { |
| 27 | + it('RunAtLoad=false when shouldAutoStart=false', async () => { |
| 28 | + process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART = 'false' |
| 29 | + const svc = makeServiceInstance('redis') |
| 30 | + const plist = generateLaunchdPlist(svc) |
| 31 | + expect(plist.RunAtLoad).toBe(false) |
| 32 | + delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART |
| 33 | + }) |
| 34 | + |
| 35 | + it('RunAtLoad=true when shouldAutoStart=true', async () => { |
| 36 | + process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART = 'true' |
| 37 | + const svc = makeServiceInstance('postgres') |
| 38 | + const plist = generateLaunchdPlist(svc) |
| 39 | + expect(plist.RunAtLoad).toBe(true) |
| 40 | + delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART |
| 41 | + }) |
| 42 | + |
| 43 | + it('RunAtLoad defaults to service.enabled when shouldAutoStart not set', async () => { |
| 44 | + delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART |
| 45 | + const svc = makeServiceInstance('postgres', { enabled: true }) |
| 46 | + const plist = generateLaunchdPlist(svc) |
| 47 | + expect(plist.RunAtLoad).toBe(true) |
| 48 | + }) |
| 49 | +}) |
0 commit comments