Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 196858b

Browse filesBrowse files
authored
Merge pull request #1664 from mstruebing/ms/websocket
[RELEASE-1.x] fix: use correct types for websocket
2 parents e95602d + ffed804 commit 196858b
Copy full SHA for 196858b

File tree

Expand file treeCollapse file tree

8 files changed

+50
-41
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+50
-41
lines changed

‎src/attach.ts

Copy file name to clipboardExpand all lines: src/attach.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Attach {
2323
stderr: stream.Writable | any,
2424
stdin: stream.Readable | any,
2525
tty: boolean,
26-
): Promise<WebSocket> {
26+
): Promise<WebSocket.WebSocket> {
2727
const query = {
2828
container: containerName,
2929
stderr: stderr != null,

‎src/attach_test.ts

Copy file name to clipboardExpand all lines: src/attach_test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Attach', () => {
4949
it('should correctly attach to streams', async () => {
5050
const kc = new KubeConfig();
5151
const fakeWebSocketInterface: WebSocketInterface = mock(WebSocketHandler);
52-
const fakeWebSocket: WebSocket = mock(WebSocket);
52+
const fakeWebSocket: WebSocket.WebSocket = mock(WebSocket);
5353
const callAwaiter: CallAwaiter = new CallAwaiter();
5454
const attach = new Attach(kc, instance(fakeWebSocketInterface));
5555
const osStream = new ResizableWriteableStreamBuffer();
@@ -63,7 +63,7 @@ describe('Attach', () => {
6363
const path = `/api/v1/namespaces/${namespace}/pods/${pod}/attach`;
6464
const args = `container=${container}&stderr=true&stdin=true&stdout=true&tty=false`;
6565

66-
const fakeConn: WebSocket = instance(fakeWebSocket);
66+
const fakeConn: WebSocket.WebSocket = instance(fakeWebSocket);
6767
when(fakeWebSocketInterface.connect(`${path}?${args}`, null, anyFunction())).thenResolve(
6868
fakeConn,
6969
);

‎src/cp_test.ts

Copy file name to clipboardExpand all lines: src/cp_test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Cp', () => {
4444
it('should run extract tar command to a url', async () => {
4545
const kc = new KubeConfig();
4646
const fakeWebSocketInterface: WebSocketInterface = mock(WebSocketHandler);
47-
const fakeWebSocket: WebSocket = mock(WebSocket) as WebSocket;
47+
const fakeWebSocket: WebSocket.WebSocket = mock(WebSocket) as WebSocket.WebSocket;
4848
const callAwaiter: CallAwaiter = new CallAwaiter();
4949
const exec = new Exec(kc, instance(fakeWebSocketInterface));
5050
const cp = new Cp(kc, exec);
@@ -67,7 +67,7 @@ describe('Cp', () => {
6767
};
6868
const queryStr = querystring.stringify(query);
6969

70-
const fakeConn: WebSocket = instance(fakeWebSocket);
70+
const fakeConn: WebSocket.WebSocket = instance(fakeWebSocket);
7171
when(fakeWebSocketInterface.connect(`${path}?${queryStr}`, null, anyFunction())).thenResolve(
7272
fakeConn,
7373
);

‎src/exec.ts

Copy file name to clipboardExpand all lines: src/exec.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class Exec {
2727
* @param {boolean} tty - Should the command execute in a TTY enabled session.
2828
* @param {(V1Status) => void} statusCallback -
2929
* A callback to received the status (e.g. exit code) from the command, optional.
30-
* @return {string} This is the result
30+
* @return {Promise<WebSocket>} A promise that will return the web socket created for this command.
3131
*/
3232
public async exec(
3333
namespace: string,
@@ -39,7 +39,7 @@ export class Exec {
3939
stdin: stream.Readable | null,
4040
tty: boolean,
4141
statusCallback?: (status: V1Status) => void,
42-
): Promise<WebSocket> {
42+
): Promise<WebSocket.WebSocket> {
4343
const query = {
4444
stdout: stdout != null,
4545
stderr: stderr != null,

‎src/exec_test.ts

Copy file name to clipboardExpand all lines: src/exec_test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Exec', () => {
5656
it('should correctly attach to streams', async () => {
5757
const kc = new KubeConfig();
5858
const fakeWebSocketInterface: WebSocketInterface = mock(WebSocketHandler);
59-
const fakeWebSocket: WebSocket = mock(WebSocket);
59+
const fakeWebSocket: WebSocket.WebSocket = mock(WebSocket);
6060
const callAwaiter: CallAwaiter = new CallAwaiter();
6161
const exec = new Exec(kc, instance(fakeWebSocketInterface));
6262
const osStream = new ResizableWriteableStreamBuffer();
@@ -73,7 +73,7 @@ describe('Exec', () => {
7373

7474
let statusOut = {} as V1Status;
7575

76-
const fakeConn: WebSocket = instance(fakeWebSocket);
76+
const fakeConn: WebSocket.WebSocket = instance(fakeWebSocket);
7777
when(fakeWebSocketInterface.connect(`${path}?${args}`, null, anyFunction())).thenResolve(
7878
fakeConn,
7979
);

‎src/portforward.ts

Copy file name to clipboardExpand all lines: src/portforward.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class PortForward {
2525
err: stream.Writable | null,
2626
input: stream.Readable,
2727
retryCount: number = 0,
28-
): Promise<WebSocket | (() => WebSocket | null)> {
28+
): Promise<WebSocket.WebSocket | (() => WebSocket.WebSocket | null)> {
2929
if (targetPorts.length === 0) {
3030
throw new Error('You must provide at least one port to forward to.');
3131
}
@@ -42,7 +42,7 @@ export class PortForward {
4242
needsToReadPortNumber[index * 2 + 1] = true;
4343
});
4444
const path = `/api/v1/namespaces/${namespace}/pods/${podName}/portforward?${queryStr}`;
45-
const createWebSocket = (): Promise<WebSocket> => {
45+
const createWebSocket = (): Promise<WebSocket.WebSocket> => {
4646
return this.handler.connect(path, null, (streamNum: number, buff: Buffer | string): boolean => {
4747
if (streamNum >= targetPorts.length * 2) {
4848
return !this.disconnectOnErr;

‎src/web-socket-handler.ts

Copy file name to clipboardExpand all lines: src/web-socket-handler.ts
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface WebSocketInterface {
1111
path: string,
1212
textHandler: ((text: string) => boolean) | null,
1313
binaryHandler: ((stream: number, buff: Buffer) => boolean) | null,
14-
): Promise<WebSocket>;
14+
): Promise<WebSocket.WebSocket>;
1515
}
1616

1717
export class WebSocketHandler implements WebSocketInterface {
@@ -50,7 +50,7 @@ export class WebSocketHandler implements WebSocketInterface {
5050
}
5151

5252
public static handleStandardInput(
53-
ws: WebSocket,
53+
ws: WebSocket.WebSocket,
5454
stdin: stream.Readable | any,
5555
streamNum: number = 0,
5656
): boolean {
@@ -74,11 +74,11 @@ export class WebSocketHandler implements WebSocketInterface {
7474

7575
public static async processData(
7676
data: string | Buffer,
77-
ws: WebSocket | null,
78-
createWS: () => Promise<WebSocket>,
77+
ws: WebSocket.WebSocket | null,
78+
createWS: () => Promise<WebSocket.WebSocket>,
7979
streamNum: number = 0,
8080
retryCount: number = 3,
81-
): Promise<WebSocket | null> {
81+
): Promise<WebSocket.WebSocket | null> {
8282
const buff = Buffer.alloc(data.length + 1);
8383

8484
buff.writeInt8(streamNum, 0);
@@ -108,17 +108,17 @@ export class WebSocketHandler implements WebSocketInterface {
108108
}
109109

110110
public static restartableHandleStandardInput(
111-
createWS: () => Promise<WebSocket>,
111+
createWS: () => Promise<WebSocket.WebSocket>,
112112
stdin: stream.Readable | any,
113113
streamNum: number = 0,
114114
retryCount: number = 3,
115-
): () => WebSocket | null {
115+
): () => WebSocket.WebSocket | null {
116116
if (retryCount < 0) {
117117
throw new Error("retryCount can't be lower than 0.");
118118
}
119119

120120
let queue: Promise<void> = Promise.resolve();
121-
let ws: WebSocket | null = null;
121+
let ws: WebSocket.WebSocket | null = null;
122122

123123
stdin.on('data', (data) => {
124124
queue = queue.then(async () => {
@@ -138,7 +138,7 @@ export class WebSocketHandler implements WebSocketInterface {
138138
// factory is really just for test injection
139139
public constructor(
140140
readonly config: KubeConfig,
141-
readonly socketFactory?: (uri: string, opts: WebSocket.ClientOptions) => WebSocket,
141+
readonly socketFactory?: (uri: string, opts: WebSocket.ClientOptions) => WebSocket.WebSocket,
142142
) {}
143143

144144
/**
@@ -153,7 +153,7 @@ export class WebSocketHandler implements WebSocketInterface {
153153
path: string,
154154
textHandler: ((text: string) => boolean) | null,
155155
binaryHandler: ((stream: number, buff: Buffer) => boolean) | null,
156-
): Promise<WebSocket> {
156+
): Promise<WebSocket.WebSocket> {
157157
const cluster = this.config.getCurrentCluster();
158158
if (!cluster) {
159159
throw new Error('No cluster is defined.');
@@ -168,7 +168,7 @@ export class WebSocketHandler implements WebSocketInterface {
168168

169169
await this.config.applyToHTTPSOptions(opts);
170170

171-
return await new Promise<WebSocket>((resolve, reject) => {
171+
return await new Promise<WebSocket.WebSocket>((resolve, reject) => {
172172
const client = this.socketFactory
173173
? this.socketFactory(uri, opts)
174174
: new WebSocket(uri, protocols, opts);

‎src/web-socket-handler_test.ts

Copy file name to clipboardExpand all lines: src/web-socket-handler_test.ts
+28-19Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,16 @@ describe('WebSocket', () => {
113113
} as User,
114114
];
115115

116-
const mockWs = {} as WebSocket;
116+
const mockWs = {} as WebSocket.WebSocket;
117117
let uriOut = '';
118118

119-
const handler = new WebSocketHandler(kc, (uri: string, opts: WebSocket.ClientOptions): WebSocket => {
120-
uriOut = uri;
121-
return mockWs as WebSocket;
122-
});
119+
const handler = new WebSocketHandler(
120+
kc,
121+
(uri: string, opts: WebSocket.ClientOptions): WebSocket.WebSocket => {
122+
uriOut = uri;
123+
return mockWs as WebSocket.WebSocket;
124+
},
125+
);
123126
const path = '/some/path';
124127

125128
const promise = handler.connect(path, null, null);
@@ -162,13 +165,16 @@ describe('WebSocket', () => {
162165
} as User,
163166
];
164167

165-
const mockWs = {} as WebSocket;
168+
const mockWs = {} as WebSocket.WebSocket;
166169
let uriOut = '';
167170

168-
const handler = new WebSocketHandler(kc, (uri: string, opts: WebSocket.ClientOptions): WebSocket => {
169-
uriOut = uri;
170-
return mockWs as WebSocket;
171-
});
171+
const handler = new WebSocketHandler(
172+
kc,
173+
(uri: string, opts: WebSocket.ClientOptions): WebSocket.WebSocket => {
174+
uriOut = uri;
175+
return mockWs as WebSocket.WebSocket;
176+
},
177+
);
172178
const path = '/some/path';
173179

174180
const promise = handler.connect(path, null, null);
@@ -229,13 +235,16 @@ describe('WebSocket', () => {
229235
close: () => {
230236
closeCount++;
231237
},
232-
} as WebSocket;
238+
} as WebSocket.WebSocket;
233239
let uriOut = '';
234240

235-
const handler = new WebSocketHandler(kc, (uri: string, opts: WebSocket.ClientOptions): WebSocket => {
236-
uriOut = uri;
237-
return mockWs as WebSocket;
238-
});
241+
const handler = new WebSocketHandler(
242+
kc,
243+
(uri: string, opts: WebSocket.ClientOptions): WebSocket.WebSocket => {
244+
uriOut = uri;
245+
return mockWs as WebSocket.WebSocket;
246+
},
247+
);
239248
const path = '/some/path';
240249

241250
let textReceived = '';
@@ -298,7 +307,7 @@ describe('WebSocket', () => {
298307

299308
describe('Restartable Handle Standard Input', () => {
300309
it('should throw on negative retry', () => {
301-
const p = new Promise<WebSocket>(() => {});
310+
const p = new Promise<WebSocket.WebSocket>(() => {});
302311
expect(() => WebSocketHandler.restartableHandleStandardInput(() => p, null, 0, -1)).to.throw(
303312
"retryCount can't be lower than 0.",
304313
);
@@ -313,10 +322,10 @@ describe('Restartable Handle Standard Input', () => {
313322
WebSocketHandler.processData(
314323
'some test data',
315324
null,
316-
(): Promise<WebSocket> => {
317-
return new Promise<WebSocket>((resolve) => {
325+
(): Promise<WebSocket.WebSocket> => {
326+
return new Promise<WebSocket.WebSocket>((resolve) => {
318327
count++;
319-
resolve(ws as WebSocket);
328+
resolve(ws as WebSocket.WebSocket);
320329
});
321330
},
322331
0,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.