1
1
import { expect } from 'chai' ;
2
- import { EventEmitter } from 'events' ;
3
2
import WebSocket = require( 'isomorphic-ws' ) ;
4
3
import { ReadableStreamBuffer , WritableStreamBuffer } from 'stream-buffers' ;
5
4
import { anyFunction , anything , capture , instance , mock , verify , when } from 'ts-mockito' ;
6
- import { CallAwaiter , matchBuffer } from '../test' ;
7
5
6
+ import { CallAwaiter , matchBuffer , ResizableWriteableStreamBuffer } from '../test' ;
8
7
import { Attach } from './attach' ;
9
8
import { KubeConfig } from './config' ;
10
- import { TerminalSize , TerminalSizeQueue } from './terminal-size-queue' ;
9
+ import { TerminalSize } from './terminal-size-queue' ;
11
10
import { WebSocketHandler , WebSocketInterface } from './web-socket-handler' ;
12
11
13
12
describe ( 'Attach' , ( ) => {
@@ -53,10 +52,9 @@ describe('Attach', () => {
53
52
const fakeWebSocket : WebSocket = mock ( WebSocket ) ;
54
53
const callAwaiter : CallAwaiter = new CallAwaiter ( ) ;
55
54
const attach = new Attach ( kc , instance ( fakeWebSocketInterface ) ) ;
56
- const osStream = new WritableStreamBuffer ( ) ;
55
+ const osStream = new ResizableWriteableStreamBuffer ( ) ;
57
56
const errStream = new WritableStreamBuffer ( ) ;
58
57
const isStream = new ReadableStreamBuffer ( ) ;
59
- const terminalSizeQueue = new TerminalSizeQueue ( ) ;
60
58
61
59
const namespace = 'somenamespace' ;
62
60
const pod = 'somepod' ;
@@ -72,16 +70,7 @@ describe('Attach', () => {
72
70
when ( fakeWebSocket . send ( anything ( ) ) ) . thenCall ( callAwaiter . resolveCall ( 'send' ) ) ;
73
71
when ( fakeWebSocket . close ( ) ) . thenCall ( callAwaiter . resolveCall ( 'close' ) ) ;
74
72
75
- await attach . attach (
76
- namespace ,
77
- pod ,
78
- container ,
79
- osStream ,
80
- errStream ,
81
- isStream ,
82
- false ,
83
- terminalSizeQueue ,
84
- ) ;
73
+ await attach . attach ( namespace , pod , container , osStream , errStream , isStream , false ) ;
85
74
const [ , , outputFn ] = capture ( fakeWebSocketInterface . connect ) . last ( ) ;
86
75
87
76
/* tslint:disable:no-unused-expression */
@@ -109,6 +98,14 @@ describe('Attach', () => {
109
98
expect ( buff [ i ] ) . to . equal ( 20 ) ;
110
99
}
111
100
101
+ const initialTerminalSize : TerminalSize = { height : 0 , width : 0 } ;
102
+ await callAwaiter . awaitCall ( 'send' ) ;
103
+ verify (
104
+ fakeWebSocket . send (
105
+ matchBuffer ( WebSocketHandler . ResizeStream , JSON . stringify ( initialTerminalSize ) ) ,
106
+ ) ,
107
+ ) . called ( ) ;
108
+
112
109
const msg = 'This is test data' ;
113
110
const inputPromise = callAwaiter . awaitCall ( 'send' ) ;
114
111
isStream . put ( msg ) ;
@@ -117,7 +114,9 @@ describe('Attach', () => {
117
114
118
115
const terminalSize : TerminalSize = { height : 80 , width : 120 } ;
119
116
const resizePromise = callAwaiter . awaitCall ( 'send' ) ;
120
- terminalSizeQueue . resize ( terminalSize ) ;
117
+ osStream . rows = terminalSize . height ;
118
+ osStream . columns = terminalSize . width ;
119
+ osStream . emit ( 'resize' ) ;
121
120
await resizePromise ;
122
121
verify (
123
122
fakeWebSocket . send ( matchBuffer ( WebSocketHandler . ResizeStream , JSON . stringify ( terminalSize ) ) ) ,
0 commit comments