Skip to content

Commit c700dd4

Browse files
authored
refactor(MinikubeDownload): expose extension executable path (#170)
* refactor(MinikubeDownload): expose extension executable path Signed-off-by: axel7083 <[email protected]> * fix: prettier Signed-off-by: axel7083 <[email protected]> --------- Signed-off-by: axel7083 <[email protected]>
1 parent 53909f2 commit c700dd4

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/download.spec.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { beforeEach } from 'node:test';
2222

2323
import type { Octokit } from '@octokit/rest';
2424
import type * as extensionApi from '@podman-desktop/api';
25-
import { afterEach, expect, test, vi } from 'vitest';
25+
import { env } from '@podman-desktop/api';
26+
import { afterEach, describe, expect, test, vi } from 'vitest';
2627

2728
import type { MinikubeGithubReleaseArtifactMetadata } from './download';
2829
import { MinikubeDownload } from './download';
@@ -49,6 +50,14 @@ const releases: MinikubeGithubReleaseArtifactMetadata[] = [
4950
};
5051
});
5152

53+
vi.mock('@podman-desktop/api', () => ({
54+
env: {
55+
isWindows: false,
56+
isLinux: false,
57+
isMac: false,
58+
},
59+
}));
60+
5261
const listReleaseAssetsMock = vi.fn();
5362
const listReleasesMock = vi.fn();
5463
const getReleaseAssetMock = vi.fn();
@@ -132,3 +141,19 @@ test('test download of minikube passes and that mkdir and executable mocks are c
132141
expect(mkdirMock).toHaveBeenCalled();
133142
expect(makeExecutableMock).toHaveBeenCalled();
134143
});
144+
145+
describe('getMinikubeExtensionPath', () => {
146+
test('window platform should add .exe suffix', async () => {
147+
(env.isWindows as boolean) = true;
148+
149+
const minikubeDownload = new MinikubeDownload(extensionContext, octokitMock);
150+
expect(minikubeDownload.getMinikubeExtensionPath()).toStrictEqual(expect.stringMatching('.*\\minikube.exe$'));
151+
});
152+
153+
test('non-window platform should not add .exe suffix', async () => {
154+
(env.isWindows as boolean) = false;
155+
156+
const minikubeDownload = new MinikubeDownload(extensionContext, octokitMock);
157+
expect(minikubeDownload.getMinikubeExtensionPath()).toStrictEqual(expect.stringMatching('.*\\minikube$'));
158+
});
159+
});

src/download.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as path from 'node:path';
2323

2424
import type { Octokit } from '@octokit/rest';
2525
import type * as extensionApi from '@podman-desktop/api';
26+
import { env } from '@podman-desktop/api';
2627

2728
export interface MinikubeGithubReleaseArtifactMetadata {
2829
tag: string;
@@ -65,6 +66,14 @@ export class MinikubeDownload {
6566
return latestReleases[0];
6667
}
6768

69+
getMinikubeExtensionPath(): string {
70+
let fileExtension = '';
71+
if (env.isWindows) {
72+
fileExtension = '.exe';
73+
}
74+
return path.resolve(this.extensionContext.storagePath, `minikube${fileExtension}`);
75+
}
76+
6877
// Download minikube from the artifact metadata: MinikubeGithubReleaseArtifactMetadata
6978
// this will download it to the storage bin folder as well as make it executable
7079
// return the path where the file has been downloaded
@@ -74,17 +83,12 @@ export class MinikubeDownload {
7483

7584
// Get the storage and check to see if it exists before we download kubectl
7685
const storageData = this.extensionContext.storagePath;
77-
const storageBinFolder = path.resolve(storageData, 'bin');
78-
if (!existsSync(storageBinFolder)) {
79-
await promises.mkdir(storageBinFolder, { recursive: true });
86+
if (!existsSync(storageData)) {
87+
await promises.mkdir(storageData, { recursive: true });
8088
}
8189

8290
// Correct the file extension and path resolution
83-
let fileExtension = '';
84-
if (process.platform === 'win32') {
85-
fileExtension = '.exe';
86-
}
87-
const minikubeDownloadLocation = path.resolve(storageBinFolder, `minikube${fileExtension}`);
91+
const minikubeDownloadLocation = this.getMinikubeExtensionPath();
8892

8993
// Download the asset and make it executable
9094
await this.downloadReleaseAsset(assetId, minikubeDownloadLocation);

0 commit comments

Comments
 (0)