Skip to content

Commit 8352e16

Browse files
authored
Merge pull request #2112 from cjihrig/mv-test-dir
src: move test directory under `src/`
2 parents 980765f + e508774 commit 8352e16

15 files changed

+101
-98
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"exclude": [
3838
"src/gen/*/**.ts",
3939
"src/index.ts",
40-
"src/*_test.ts"
40+
"src/*_test.ts",
41+
"src/test"
4142
],
4243
"extension": [
4344
".ts"

src/attach_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws';
33
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
44
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';
55

6-
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
6+
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test';
77
import { Attach } from './attach.js';
88
import { KubeConfig } from './config.js';
99
import { TerminalSize } from './terminal-size-queue.js';

src/azure_auth_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe('AzureAuth', () => {
297297
authProvider: {
298298
name: 'azure',
299299
config: {
300-
'cmd-path': join(__dirname, '..', 'test', 'echo space.js'),
300+
'cmd-path': join(__dirname, 'test', 'echo space.js'),
301301
'cmd-args': `'${responseStr}'`,
302302
'token-key': '{.token.accessToken}',
303303
'expiry-key': '{.token.token_expiry}',

src/config_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import mockfs from 'mock-fs';
1010

1111
import { Headers } from 'node-fetch';
1212
import { HttpMethod } from './index.js';
13-
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from '../test/match-buffer';
13+
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer';
1414
import { CoreV1Api, RequestContext } from './api.js';
1515
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config.js';
1616
import { ActionOnInvalid, Cluster, newClusters, newContexts, newUsers, User } from './config_types.js';
@@ -1067,7 +1067,7 @@ describe('KubeConfig', () => {
10671067
authProvider: {
10681068
name: 'azure', // applies to gcp too as they are both handled by CloudAuth class
10691069
config: {
1070-
'cmd-path': path.join(__dirname, '..', 'test', 'echo space.js'),
1070+
'cmd-path': path.join(__dirname, 'test', 'echo space.js'),
10711071
'cmd-args': `'${responseStr}'`,
10721072
'token-key': '{.token.accessToken}',
10731073
'expiry-key': '{.token.token_expiry}',

src/cp_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { anything, anyFunction, instance, mock, verify, when } from 'ts-mockito'
22
import querystring from 'node:querystring';
33
import WebSocket from 'isomorphic-ws';
44

5-
import { CallAwaiter } from '../test';
5+
import { CallAwaiter } from './test';
66
import { KubeConfig } from './config.js';
77
import { Exec } from './exec.js';
88
import { Cp } from './cp.js';

src/exec_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws';
33
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
44
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';
55

6-
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
6+
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test';
77
import { V1Status } from './api.js';
88
import { KubeConfig } from './config.js';
99
import { Exec } from './exec.js';

src/gcp_auth_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('GoogleCloudPlatformAuth', () => {
282282
authProvider: {
283283
name: 'gcp',
284284
config: {
285-
'cmd-path': join(__dirname, '..', 'test', 'echo space.js'),
285+
'cmd-path': join(__dirname, 'test', 'echo space.js'),
286286
'cmd-args': `'${responseStr}'`,
287287
'token-key': '{.token.accessToken}',
288288
'expiry-key': '{.token.token_expiry}',

src/test/call-awaiter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { EventEmitter } from 'node:events';
2+
3+
export class CallAwaiter extends EventEmitter {
4+
public awaitCall(event: string) {
5+
return new Promise<any[]>((resolve) => {
6+
this.once(event, resolve);
7+
});
8+
}
9+
10+
public resolveCall(event: string) {
11+
return (...args: any[]) => this.emit(event, ...args);
12+
}
13+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
22

33
// Just echo back all the args
4-
console.log(process.argv.slice(2).join(' '))
4+
console.log(process.argv.slice(2).join(' '));
File renamed without changes.

src/test/match-buffer.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { expect } from 'chai';
2+
import { RequestOptions, Agent } from 'node:https';
3+
import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher';
4+
5+
export function matchBuffer(channel: number, contents: string): StringBufferMatcher {
6+
return new StringBufferMatcher(channel, contents);
7+
}
8+
9+
class StringBufferMatcher extends Matcher {
10+
constructor(
11+
private channel: number,
12+
private contents: string,
13+
) {
14+
super();
15+
}
16+
17+
public valueOf(): string {
18+
return this.contents;
19+
}
20+
21+
public match(value: any): boolean {
22+
if (value instanceof Buffer) {
23+
const buffer = value as Buffer;
24+
const channel: number = buffer.readInt8(0);
25+
const contents: string = buffer.toString('utf8', 1);
26+
return this.channel === channel && this.contents === contents;
27+
}
28+
29+
return false;
30+
}
31+
32+
public toString(): string {
33+
return `buffer did not contain "${this.contents}"`;
34+
}
35+
}
36+
37+
export function assertRequestAgentsEqual(agent1: Agent, agent2: Agent): void {
38+
const BUFFER_EQUAL_TRUE = 0;
39+
const ca1 = agent1.options.ca;
40+
const ca2 = agent2.options.ca;
41+
//@ts-ignore
42+
if (ca1 !== ca2 && Buffer.compare(ca1, ca2) !== BUFFER_EQUAL_TRUE) {
43+
throw 'unequal agent ca buffer';
44+
}
45+
const cert1 = agent1.options.cert;
46+
const cert2 = agent2.options.cert;
47+
//@ts-ignore
48+
if (cert1 !== cert2 && Buffer.compare(cert1, cert2) !== BUFFER_EQUAL_TRUE) {
49+
throw 'unequal agent cert buffer';
50+
}
51+
52+
const key1 = agent1.options.key;
53+
const key2 = agent2.options.key;
54+
//@ts-ignore
55+
if (key1 !== key2 && Buffer.compare(key1, key2) !== BUFFER_EQUAL_TRUE) {
56+
throw 'unequal agent key buffer';
57+
}
58+
59+
expect(agent1.options.passphrase).to.equal(agent2.options.passphrase);
60+
expect(agent1.options.pfx).to.equal(agent2.options.pfx);
61+
expect(agent1.options.rejectUnauthorized).to.equal(agent2.options.rejectUnauthorized);
62+
}
63+
64+
export function assertRequestOptionsEqual(options1: RequestOptions, options2: RequestOptions): void {
65+
//@ts-ignore agent has type Agent | Boolean which we expect to be populated with Agent here
66+
const agent1: Agent = options1.agent;
67+
//@ts-ignore
68+
const agent2: Agent = options2.agent;
69+
assertRequestAgentsEqual(agent1, agent2);
70+
71+
expect(options1.auth).to.equal(options2.auth);
72+
expect(options1.headers).to.deep.equal(options2.headers);
73+
expect(options1.rejectUnauthorized).to.equal(options2.rejectUnauthorized);
74+
expect(options1.servername).to.equal(options2.servername);
75+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { WritableStreamBuffer } from 'stream-buffers';
22

33
export class ResizableWriteableStreamBuffer extends WritableStreamBuffer implements NodeJS.WritableStream {
4-
public columns: number = 0;
5-
public rows: number = 0;
4+
public columns: number = 0;
5+
public rows: number = 0;
66
}

test/call-awaiter.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/match-buffer.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
// enable this when it works with tslint, or we switch to prettier
2020
// "declarationMap": true
2121
},
22-
"exclude": ["node_modules", "src/*_test.ts", "dist"],
22+
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
2323
"include": ["*.ts", "src/**/*"]
2424
}

0 commit comments

Comments
 (0)