Skip to content

Commit e7cb4d1

Browse files
committed
feat: return os.platform
1 parent f7a375f commit e7cb4d1

File tree

3 files changed

+14
-43
lines changed

3 files changed

+14
-43
lines changed

packages/channels/src/interface/system-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export interface SystemApi {
2222
openExternal(uri: string): Promise<boolean>;
2323
clipboardWriteText(text: string): Promise<void>;
2424
getFreePort(startPort: number): Promise<number>;
25-
getSystemName(): Promise<'linux' | 'mac' | 'windows' | undefined>;
25+
getPlatformName(): Promise<string>;
2626
}

packages/extension/src/manager/system-api.spec.ts

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,19 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import { describe, expect, test } from 'vitest';
19+
import { describe, expect, test, vi } from 'vitest';
2020
import { SystemApiImpl } from '/@/manager/system-api';
21-
import * as podmanDesktopApi from '@podman-desktop/api';
21+
import * as os from 'node:os';
2222

23-
describe('getSystemName', async () => {
24-
const systemApi = new SystemApiImpl();
25-
26-
test('should return linux', async () => {
27-
(podmanDesktopApi.env.isLinux as boolean) = true;
28-
(podmanDesktopApi.env.isMac as boolean) = false;
29-
(podmanDesktopApi.env.isWindows as boolean) = false;
30-
const systemName = await systemApi.getSystemName();
31-
expect(systemName).toBe('linux');
32-
});
23+
vi.mock(import('node:os'));
3324

34-
test('should return mac', async () => {
35-
(podmanDesktopApi.env.isLinux as boolean) = false;
36-
(podmanDesktopApi.env.isMac as boolean) = true;
37-
(podmanDesktopApi.env.isWindows as boolean) = false;
38-
const systemName = await systemApi.getSystemName();
39-
expect(systemName).toBe('mac');
40-
});
41-
42-
test('should return windows', async () => {
43-
(podmanDesktopApi.env.isLinux as boolean) = false;
44-
(podmanDesktopApi.env.isMac as boolean) = false;
45-
(podmanDesktopApi.env.isWindows as boolean) = true;
46-
const systemName = await systemApi.getSystemName();
47-
expect(systemName).toBe('windows');
48-
});
25+
describe('getPlatformName', async () => {
26+
const systemApi = new SystemApiImpl();
4927

50-
test('should return undefined', async () => {
51-
(podmanDesktopApi.env.isLinux as boolean) = false;
52-
(podmanDesktopApi.env.isMac as boolean) = false;
53-
(podmanDesktopApi.env.isWindows as boolean) = false;
54-
const systemName = await systemApi.getSystemName();
55-
expect(systemName).toBeUndefined();
28+
test('should return value from os.platform', async () => {
29+
// testing with a non-tested platform, to be sure that the value is not obtained from the system
30+
vi.mocked(os.platform).mockReturnValue('sunos');
31+
const platformName = await systemApi.getPlatformName();
32+
expect(platformName).toBe('sunos');
5633
});
5734
});

packages/extension/src/manager/system-api.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import { injectable } from 'inversify';
2020
import type { SystemApi } from '@kubernetes-dashboard/channels';
2121
import * as podmanDesktopApi from '@podman-desktop/api';
22+
import * as os from 'node:os';
2223

2324
@injectable()
2425
export class SystemApiImpl implements SystemApi {
@@ -34,14 +35,7 @@ export class SystemApiImpl implements SystemApi {
3435
return podmanDesktopApi.net.getFreePort(startPort);
3536
}
3637

37-
async getSystemName(): Promise<'linux' | 'mac' | 'windows' | undefined> {
38-
if (podmanDesktopApi.env.isLinux) {
39-
return 'linux';
40-
} else if (podmanDesktopApi.env.isMac) {
41-
return 'mac';
42-
} else if (podmanDesktopApi.env.isWindows) {
43-
return 'windows';
44-
}
45-
return undefined;
38+
async getPlatformName(): Promise<string> {
39+
return os.platform();
4640
}
4741
}

0 commit comments

Comments
 (0)