Skip to content

Commit 3b44c17

Browse files
committed
Address comments
1 parent 30460bc commit 3b44c17

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/config.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ export class KubeConfig implements SecurityAuthentication {
419419
}
420420
if (platform === 'win32') {
421421
try {
422-
const envKubeconfigPathResult = this.spawnSync('wsl.exe', [
422+
const envKubeconfigPathResult = child_process.spawnSync('wsl.exe', [
423423
'bash',
424424
'-c',
425425
'printenv KUBECONFIG',
426426
]);
427427
if (envKubeconfigPathResult.status === 0 && envKubeconfigPathResult.stdout.length > 0) {
428-
const result = this.spawnSync('wsl.exe', [
428+
const result = child_process.spawnSync('wsl.exe', [
429429
'cat',
430430
envKubeconfigPathResult.stdout.toString('utf8'),
431431
]);
@@ -438,10 +438,10 @@ export class KubeConfig implements SecurityAuthentication {
438438
// Falling back to default kubeconfig
439439
}
440440
try {
441-
const configResult = this.spawnSync('wsl.exe', ['cat', '~/.kube/config']);
441+
const configResult = child_process.spawnSync('wsl.exe', ['cat', '~/.kube/config']);
442442
if (configResult.status === 0) {
443443
this.loadFromString(configResult.stdout.toString('utf8'), opts);
444-
const result = this.spawnSync('wsl.exe', ['wslpath', '-w', '~/.kube']);
444+
const result = child_process.spawnSync('wsl.exe', ['wslpath', '-w', '~/.kube']);
445445
if (result.status === 0) {
446446
this.makePathsAbsolute(result.stdout.toString('utf8'));
447447
}
@@ -597,13 +597,6 @@ export class KubeConfig implements SecurityAuthentication {
597597
this.applyHTTPSOptions(opts);
598598
await this.applyAuthorizationHeader(opts);
599599
}
600-
601-
private spawnSync(
602-
command: string,
603-
args: string[],
604-
): { status: number | null; stdout: Buffer; stderr: Buffer } {
605-
return child_process.spawnSync(command, args);
606-
}
607600
}
608601

609602
export type ApiConstructor<T extends ApiType> = new (config: Configuration) => T;

src/config_test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { deepEqual, deepStrictEqual, notStrictEqual, rejects, strictEqual, throws } from 'node:assert';
2+
import child_process from 'node:child_process';
23
import { readFileSync } from 'node:fs';
34
import https from 'node:https';
45
import { Agent, RequestOptions } from 'node:https';
56
import path, { dirname, join } from 'node:path';
67
import { fileURLToPath } from 'node:url';
8+
import { mock } from 'node:test';
79

810
import mockfs from 'mock-fs';
911

@@ -324,7 +326,6 @@ describe('KubeConfig', () => {
324326
};
325327

326328
assertRequestOptionsEqual(opts, expectedOptions);
327-
console.log(requestContext.getAgent());
328329
strictEqual((requestContext.getAgent()! as any).options.servername, 'kube.example2.com');
329330
});
330331
it('should apply cert configs', async () => {
@@ -1637,10 +1638,10 @@ describe('KubeConfig', () => {
16371638
it('should try to load from WSL on Windows with wsl.exe not working', () => {
16381639
const kc = new KubeConfig();
16391640
const commands: { command: string; args: string[] }[] = [];
1640-
(kc as any).spawnSync = (cmd: string, args: string[]) => {
1641+
mock.method(child_process, 'spawnSync', (cmd: string, args: string[]) => {
16411642
commands.push({ command: cmd, args });
16421643
return { status: 1, stderr: 'some error' };
1643-
};
1644+
});
16441645
kc.loadFromDefault(undefined, false, 'win32');
16451646
strictEqual(commands.length, 2);
16461647
for (let i = 0; i < commands.length; i++) {
@@ -1657,10 +1658,10 @@ describe('KubeConfig', () => {
16571658
{ status: 0, stderr: '', stdout: configData.toString() },
16581659
];
16591660
let ix = 0;
1660-
(kc as any).spawnSync = (cmd: string, args: string[]) => {
1661+
mock.method(child_process, 'spawnSync', (cmd: string, args: string[]) => {
16611662
commands.push({ command: cmd, args });
16621663
return results[ix++];
1663-
};
1664+
});
16641665
kc.loadFromDefault(undefined, false, 'win32');
16651666
strictEqual(commands.length, 2);
16661667
for (let i = 0; i < commands.length; i++) {
@@ -1678,10 +1679,10 @@ describe('KubeConfig', () => {
16781679
{ status: 0, stderr: '', stdout: 'C:\\wsldata\\.kube' },
16791680
];
16801681
let ix = 0;
1681-
(kc as any).spawnSync = (cmd: string, args: string[]) => {
1682+
mock.method(child_process, 'spawnSync', (cmd: string, args: string[]) => {
16821683
commands.push({ command: cmd, args });
16831684
return results[ix++];
1684-
};
1685+
});
16851686
kc.loadFromDefault(undefined, false, 'win32');
16861687
strictEqual(commands.length, 3);
16871688
for (let i = 0; i < commands.length; i++) {

0 commit comments

Comments
 (0)