import { tap, expect } from '@git.zone/tstest/tapbundle'; import * as smartdaemon from '../ts/index.js'; let testSmartdaemon: smartdaemon.SmartDaemon; tap.test('should create an instance of smartdaemon', async () => { testSmartdaemon = new smartdaemon.SmartDaemon(); expect(testSmartdaemon).toBeInstanceOf(smartdaemon.SmartDaemon); }); tap.test('should detect root status correctly', async () => { const isRoot = await testSmartdaemon.systemdManager['checkIsRoot'](); console.log(`Running as root: ${isRoot}`); expect(isRoot).toBeTypeofBoolean(); }); tap.test('should create service with user/group properties', async () => { const testService = await smartdaemon.SmartDaemonService.createFromOptions( testSmartdaemon, { name: 'test-service', description: 'A test service', command: 'node test.js', workingDir: '/tmp', version: '1.0.0', user: 'www-data', group: 'www-data' } ); expect(testService.user).toEqual('www-data'); expect(testService.group).toEqual('www-data'); }); tap.test('should generate systemd unit file with User/Group directives', async () => { const testService = await smartdaemon.SmartDaemonService.createFromOptions( testSmartdaemon, { name: 'test-service', description: 'A test service', command: 'node test.js', workingDir: '/tmp', version: '1.0.0', user: 'www-data', group: 'www-data' } ); const unitFileContent = testSmartdaemon.templateManager.generateUnitFileForService(testService); console.log('Generated unit file:'); console.log(unitFileContent); expect(unitFileContent).toInclude('User=www-data'); expect(unitFileContent).toInclude('Group=www-data'); expect(unitFileContent).toInclude('# user: www-data'); expect(unitFileContent).toInclude('# group: www-data'); }); tap.test('should handle services without user/group', async () => { const testService = await smartdaemon.SmartDaemonService.createFromOptions( testSmartdaemon, { name: 'test-service-no-user', description: 'A test service without user', command: 'node test.js', workingDir: '/tmp', version: '1.0.0' } ); const unitFileContent = testSmartdaemon.templateManager.generateUnitFileForService(testService); expect(unitFileContent).not.toInclude('User='); expect(unitFileContent).not.toInclude('Group='); }); tap.test('should create smartdaemon with sudo password option', async () => { const daemonWithPassword = new smartdaemon.SmartDaemon({ sudoPassword: 'test-password' }); expect(daemonWithPassword.systemdManager.sudoPassword).toEqual('test-password'); }); export default tap.start();