test(docker): cover docker subcommand rendering paths

- add handler-level coverage for up, down, logs, config, update, and status

- exercise success, validation, follow-mode, and boxed error output paths
This commit is contained in:
Tam Nhu Tran committed 2026-03-27 15:05:17 -04:00
1 parent 5ad4303345
commit 5b9954cfad
7 files changed
+430 -33

No files matched your search

@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
let logLines: string[] = [];
let errorLines: string[] = [];
@@ -26,7 +26,6 @@ afterEach(() => {
console.log = originalConsoleLog;
console.error = originalConsoleError;
process.exitCode = originalExitCode ?? 0;
mock.restore();
});
async function loadHandleStatus() {
@@ -38,38 +37,42 @@ async function loadHandleStatus() {
describe('docker status subcommand', () => {
it('prints supervisor failure details instead of masking them as a missing container', async () => {
mock.module('../../../src/docker', () => ({
DockerExecutor: class {
async status() {
return {
compose: {
command: '',
exitCode: 0,
stdout: 'NAME STATUS',
stderr: '',
remote: false,
},
supervisor: {
command: '',
exitCode: 7,
stdout: '',
stderr: 'unix:///var/run/supervisor.sock no such file',
remote: false,
},
};
}
},
}));
const dockerModule = (await import(
'../../../src/docker'
)) as typeof import('../../../src/docker');
const originalStatus = dockerModule.DockerExecutor.prototype.status;
dockerModule.DockerExecutor.prototype.status = function () {
return {
compose: {
command: '',
exitCode: 0,
stdout: 'NAME STATUS',
stderr: '',
remote: false,
},
supervisor: {
command: '',
exitCode: 7,
stdout: '',
stderr: 'unix:///var/run/supervisor.sock no such file',
remote: false,
},
};
};
const handleStatus = await loadHandleStatus();
await handleStatus([]);
try {
const handleStatus = await loadHandleStatus();
await handleStatus([]);
const rendered = logLines.join('\n');
expect(rendered).toContain('Docker status');
expect(rendered).toContain('Supervisor status check failed');
expect(rendered).toContain('supervisor.sock no such file');
expect(rendered).not.toContain('may not be running');
expect(errorLines).toEqual([]);
expect(process.exitCode).toBe(0);
const rendered = logLines.join('\n');
expect(rendered).toContain('Docker status');
expect(rendered).toContain('Supervisor status check failed');
expect(rendered).toContain('supervisor.sock no such file');
expect(rendered).not.toContain('may not be running');
expect(errorLines).toEqual([]);
expect(process.exitCode).toBe(0);
} finally {
dockerModule.DockerExecutor.prototype.status = originalStatus;
}
});
});