Skip to content
Closed
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
16 changes: 15 additions & 1 deletion src/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { afterEach, assert, beforeEach, describe, expect, test, vi } from 'vites

import * as authentication from './authentication';
import { ImageCache } from './cache';
import { activate } from './extension';
import { activate, getJSONMachineListByProvider } from './extension';
import type { SubscriptionManagerClientV1 } from './rh-api/rh-api-sm';
import * as utils from './utils';
import * as winutils from './win/utils';
Expand Down Expand Up @@ -639,3 +639,17 @@ describe('register', () => {
});
});
});

test('Expect getJSONMachineListByProvider not to return error message for ENOENT', async () => {
vi.mocked(macadamJSPackage.Macadam.prototype.listVms).mockRejectedValueOnce(new Error('failed command, ENOENT'));

vi.mocked(macadamJSPackage.Macadam.prototype.listVms).mockRejectedValueOnce(new Error('failed command'));

const ENOENTError = await getJSONMachineListByProvider('wsl');

expect(ENOENTError).toStrictEqual({ list: [], error: '' });

const otherError = await getJSONMachineListByProvider('wsl');

expect(otherError).toStrictEqual({ list: [], error: 'Error: failed command' });
});
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ export async function getJSONMachineListByProvider(vmProvider?: string): Promise
// do not ensure binaries up to date here, as we don't want to trigger the upgrade at startup
stdout = await macadam.listVms({ containerProvider: verifyContainerProivder(vmProvider ?? '') });
} catch (err: unknown) {
stderr = `${err}`;
if (err && err instanceof Error && !err.message.includes('ENOENT')) {
stderr = `${err}`;
}
}
return {
list: stdout,
Expand Down
Loading