Skip to content

src: move test directory under src/ #2112

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

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"exclude": [
"src/gen/*/**.ts",
"src/index.ts",
"src/*_test.ts"
"src/*_test.ts",
"src/test"
],
"extension": [
".ts"
Expand Down
2 changes: 1 addition & 1 deletion src/attach_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws';
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';

import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test';
import { Attach } from './attach.js';
import { KubeConfig } from './config.js';
import { TerminalSize } from './terminal-size-queue.js';
Expand Down
2 changes: 1 addition & 1 deletion src/azure_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('AzureAuth', () => {
authProvider: {
name: 'azure',
config: {
'cmd-path': join(__dirname, '..', 'test', 'echo space.js'),
'cmd-path': join(__dirname, 'test', 'echo space.js'),
'cmd-args': `'${responseStr}'`,
'token-key': '{.token.accessToken}',
'expiry-key': '{.token.token_expiry}',
Expand Down
4 changes: 2 additions & 2 deletions src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import mockfs from 'mock-fs';

import { Headers } from 'node-fetch';
import { HttpMethod } from './index.js';
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from '../test/match-buffer';
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer';
import { CoreV1Api, RequestContext } from './api.js';
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config.js';
import { ActionOnInvalid, Cluster, newClusters, newContexts, newUsers, User } from './config_types.js';
Expand Down Expand Up @@ -1067,7 +1067,7 @@ describe('KubeConfig', () => {
authProvider: {
name: 'azure', // applies to gcp too as they are both handled by CloudAuth class
config: {
'cmd-path': path.join(__dirname, '..', 'test', 'echo space.js'),
'cmd-path': path.join(__dirname, 'test', 'echo space.js'),
'cmd-args': `'${responseStr}'`,
'token-key': '{.token.accessToken}',
'expiry-key': '{.token.token_expiry}',
Expand Down
2 changes: 1 addition & 1 deletion src/cp_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { anything, anyFunction, instance, mock, verify, when } from 'ts-mockito'
import querystring from 'node:querystring';
import WebSocket from 'isomorphic-ws';

import { CallAwaiter } from '../test';
import { CallAwaiter } from './test';
import { KubeConfig } from './config.js';
import { Exec } from './exec.js';
import { Cp } from './cp.js';
Expand Down
2 changes: 1 addition & 1 deletion src/exec_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws';
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';

import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test';
import { V1Status } from './api.js';
import { KubeConfig } from './config.js';
import { Exec } from './exec.js';
Expand Down
2 changes: 1 addition & 1 deletion src/gcp_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('GoogleCloudPlatformAuth', () => {
authProvider: {
name: 'gcp',
config: {
'cmd-path': join(__dirname, '..', 'test', 'echo space.js'),
'cmd-path': join(__dirname, 'test', 'echo space.js'),
'cmd-args': `'${responseStr}'`,
'token-key': '{.token.accessToken}',
'expiry-key': '{.token.token_expiry}',
Expand Down
13 changes: 13 additions & 0 deletions src/test/call-awaiter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EventEmitter } from 'node:events';

export class CallAwaiter extends EventEmitter {
public awaitCall(event: string) {
return new Promise<any[]>((resolve) => {
this.once(event, resolve);
});
}

public resolveCall(event: string) {
return (...args: any[]) => this.emit(event, ...args);
}
}
2 changes: 1 addition & 1 deletion test/echo space.js → src/test/echo space.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

// Just echo back all the args
console.log(process.argv.slice(2).join(' '))
console.log(process.argv.slice(2).join(' '));
File renamed without changes.
75 changes: 75 additions & 0 deletions src/test/match-buffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { expect } from 'chai';
import { RequestOptions, Agent } from 'node:https';
import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher';

export function matchBuffer(channel: number, contents: string): StringBufferMatcher {
return new StringBufferMatcher(channel, contents);
}

class StringBufferMatcher extends Matcher {
constructor(
private channel: number,
private contents: string,
) {
super();
}

public valueOf(): string {
return this.contents;
}

public match(value: any): boolean {
if (value instanceof Buffer) {
const buffer = value as Buffer;
const channel: number = buffer.readInt8(0);
const contents: string = buffer.toString('utf8', 1);
return this.channel === channel && this.contents === contents;
}

return false;
}

public toString(): string {
return `buffer did not contain "${this.contents}"`;
}
}

export function assertRequestAgentsEqual(agent1: Agent, agent2: Agent): void {
const BUFFER_EQUAL_TRUE = 0;
const ca1 = agent1.options.ca;
const ca2 = agent2.options.ca;
//@ts-ignore
if (ca1 !== ca2 && Buffer.compare(ca1, ca2) !== BUFFER_EQUAL_TRUE) {
throw 'unequal agent ca buffer';
}
const cert1 = agent1.options.cert;
const cert2 = agent2.options.cert;
//@ts-ignore
if (cert1 !== cert2 && Buffer.compare(cert1, cert2) !== BUFFER_EQUAL_TRUE) {
throw 'unequal agent cert buffer';
}

const key1 = agent1.options.key;
const key2 = agent2.options.key;
//@ts-ignore
if (key1 !== key2 && Buffer.compare(key1, key2) !== BUFFER_EQUAL_TRUE) {
throw 'unequal agent key buffer';
}

expect(agent1.options.passphrase).to.equal(agent2.options.passphrase);
expect(agent1.options.pfx).to.equal(agent2.options.pfx);
expect(agent1.options.rejectUnauthorized).to.equal(agent2.options.rejectUnauthorized);
}

export function assertRequestOptionsEqual(options1: RequestOptions, options2: RequestOptions): void {
//@ts-ignore agent has type Agent | Boolean which we expect to be populated with Agent here
const agent1: Agent = options1.agent;
//@ts-ignore
const agent2: Agent = options2.agent;
assertRequestAgentsEqual(agent1, agent2);

expect(options1.auth).to.equal(options2.auth);
expect(options1.headers).to.deep.equal(options2.headers);
expect(options1.rejectUnauthorized).to.equal(options2.rejectUnauthorized);
expect(options1.servername).to.equal(options2.servername);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WritableStreamBuffer } from 'stream-buffers';

export class ResizableWriteableStreamBuffer extends WritableStreamBuffer implements NodeJS.WritableStream {
public columns: number = 0;
public rows: number = 0;
public columns: number = 0;
public rows: number = 0;
}
13 changes: 0 additions & 13 deletions test/call-awaiter.ts

This file was deleted.

73 changes: 0 additions & 73 deletions test/match-buffer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
// enable this when it works with tslint, or we switch to prettier
// "declarationMap": true
},
"exclude": ["node_modules", "src/*_test.ts", "dist"],
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
"include": ["*.ts", "src/**/*"]
}
Loading