-
Notifications
You must be signed in to change notification settings - Fork 557
Improve coverage and testability of config.ts #2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,8 +301,10 @@ describe('KubeConfig', () => { | |
const kc = new KubeConfig(); | ||
kc.loadFromFile(kcTlsServerNameFileName); | ||
|
||
const requestContext = new RequestContext('https://kube.example.com', HttpMethod.GET); | ||
const opts: https.RequestOptions = {}; | ||
await kc.applyToHTTPSOptions(opts); | ||
await kc.applySecurityAuthentication(requestContext); | ||
|
||
const expectedAgent = new https.Agent({ | ||
ca: Buffer.from('CADATA2', 'utf-8'), | ||
|
@@ -322,6 +324,8 @@ describe('KubeConfig', () => { | |
}; | ||
|
||
assertRequestOptionsEqual(opts, expectedOptions); | ||
console.log(requestContext.getAgent()); | ||
strictEqual((requestContext.getAgent()! as any).options.servername, 'kube.example2.com'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this rather an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. options isn't exposed as public (at least not in the typings), so Typescript doesn't like it. The cast as |
||
}); | ||
it('should apply cert configs', async () => { | ||
const kc = new KubeConfig(); | ||
|
@@ -1630,5 +1634,60 @@ describe('KubeConfig', () => { | |
strictEqual(inputData!.toString(), data); | ||
mockfs.restore(); | ||
}); | ||
it('should try to load from WSL on Windows with wsl.exe not working', () => { | ||
const kc = new KubeConfig(); | ||
const commands: { command: string; args: string[] }[] = []; | ||
(kc as any).spawnSync = (cmd: string, args: string[]) => { | ||
|
||
commands.push({ command: cmd, args }); | ||
return { status: 1, stderr: 'some error' }; | ||
}; | ||
kc.loadFromDefault(undefined, false, 'win32'); | ||
strictEqual(commands.length, 2); | ||
for (let i = 0; i < commands.length; i++) { | ||
strictEqual(commands[i].command, 'wsl.exe'); | ||
} | ||
}); | ||
it('should try to load from WSL on Windows with $KUBECONFIG', () => { | ||
const kc = new KubeConfig(); | ||
const test_path = 'C:\\Users\\user\\.kube\\config'; | ||
const configData = readFileSync(kcFileName); | ||
const commands: { command: string; args: string[] }[] = []; | ||
const results: { status: number; stderr: string; stdout: string }[] = [ | ||
{ status: 0, stderr: '', stdout: test_path }, | ||
{ status: 0, stderr: '', stdout: configData.toString() }, | ||
]; | ||
let ix = 0; | ||
(kc as any).spawnSync = (cmd: string, args: string[]) => { | ||
commands.push({ command: cmd, args }); | ||
return results[ix++]; | ||
}; | ||
kc.loadFromDefault(undefined, false, 'win32'); | ||
strictEqual(commands.length, 2); | ||
for (let i = 0; i < commands.length; i++) { | ||
strictEqual(commands[i].command, 'wsl.exe'); | ||
} | ||
validateFileLoad(kc); | ||
}); | ||
it('should try to load from WSL on Windows without $KUBECONFIG', () => { | ||
const kc = new KubeConfig(); | ||
const configData = readFileSync(kcFileName); | ||
const commands: { command: string; args: string[] }[] = []; | ||
const results: { status: number; stderr: string; stdout: string }[] = [ | ||
{ status: 1, stderr: 'Some Error', stdout: '' }, | ||
{ status: 0, stderr: '', stdout: configData.toString() }, | ||
{ status: 0, stderr: '', stdout: 'C:\\wsldata\\.kube' }, | ||
]; | ||
let ix = 0; | ||
(kc as any).spawnSync = (cmd: string, args: string[]) => { | ||
commands.push({ command: cmd, args }); | ||
return results[ix++]; | ||
}; | ||
kc.loadFromDefault(undefined, false, 'win32'); | ||
strictEqual(commands.length, 3); | ||
for (let i = 0; i < commands.length; i++) { | ||
strictEqual(commands[i].command, 'wsl.exe'); | ||
} | ||
validateFileLoad(kc); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.