Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

jobs:
publish:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vi.mock('../ui/spinner', () => ({
createSpinner: vi.fn(() => ({
start: vi.fn().mockReturnThis(),
stop: vi.fn().mockReturnThis(),
fail: vi.fn().mockReturnThis(),
})),
}));

Expand Down
1 change: 1 addition & 0 deletions src/__tests__/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vi.mock('../ui/spinner', () => ({
createSpinner: vi.fn(() => ({
start: vi.fn().mockReturnThis(),
stop: vi.fn().mockReturnThis(),
fail: vi.fn().mockReturnThis(),
})),
}));

Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getRunningContainers } from '../docker/containers';
import { getRunningPods } from '../kubernetes/pods';
import { logger } from '../utils/logger';
import { showRunners, showPods } from '../commands/show';
import { createSpinner } from '../ui/spinner';
import * as tableUtils from '../ui/table';

// Mock dependencies
Expand Down Expand Up @@ -47,6 +48,13 @@ describe('show command runners', () => {

// Verify: Warning was logged for Kubernetes, but no crash
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Kubernetes is unreachable'));

// Verify spinner lifecycle
expect(createSpinner).toHaveBeenCalled();
const spinnerInstance = vi.mocked(createSpinner).mock.results[0].value;
expect(spinnerInstance.start).toHaveBeenCalled();
expect(spinnerInstance.warn).toHaveBeenCalledWith(expect.stringContaining('Some runners could not be fetched'));

// Verify: Table still rendered with Docker data
expect(tableUtils.renderTable).toHaveBeenCalled();
});
Expand All @@ -60,12 +68,20 @@ describe('show command runners', () => {
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Docker is unreachable'));
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Kubernetes is unreachable'));
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('No running containers or pods found'));

// Verify spinner lifecycle
const spinnerInstance = vi.mocked(createSpinner).mock.results[0].value;
expect(spinnerInstance.warn).toHaveBeenCalledWith(expect.stringContaining('Some runners could not be fetched'));
});

it('should handle Kubernetes connection failure gracefully in showPods', async () => {
(getRunningPods as any).mockRejectedValue(new Error('EHOSTUNREACH'));

// Should not throw
await expect(showPods()).resolves.not.toThrow();

// Verify spinner lifecycle
const spinnerInstance = vi.mocked(createSpinner).mock.results[0].value;
expect(spinnerInstance.fail).toHaveBeenCalledWith(expect.stringContaining('Failed to fetch Kubernetes pods'));
});
});
4 changes: 3 additions & 1 deletion src/commands/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const run = async () => {
showWelcomeBanner('1.1.0');

const spinner = createSpinner('Checking connections...').start();
let hadError = false;
try {
const [dockerStatus, k8sStatus, minikubeStatus] = await Promise.all([
checkDockerConnection(),
Expand Down Expand Up @@ -65,10 +66,11 @@ const run = async () => {
console.log(chalk.bold('Commands:\n'));
console.log(` kdm show runners\n kdm health all\n kdm watch\n kdm logs <name>\n`);
} catch (error) {
hadError = true;
spinner.fail(`Connection check failed: ${(error as Error).message}`);
} finally {
program.outputHelp();
process.exit(0);
process.exit(hadError ? 1 : 0);
}
}

Expand Down
Loading