@@ -3,14 +3,12 @@ import WebSocket = require('isomorphic-ws');
3
3
import { ReadableStreamBuffer , WritableStreamBuffer } from 'stream-buffers' ;
4
4
import { anyFunction , capture , instance , mock , verify , when } from 'ts-mockito' ;
5
5
6
+ import { V1Status } from './api' ;
6
7
import { KubeConfig } from './config' ;
7
8
import { Exec } from './exec' ;
8
9
import { WebSocketHandler , WebSocketInterface } from './web-socket-handler' ;
9
10
10
11
describe ( 'Exec' , ( ) => {
11
- // tslint:disable-next-line:no-empty
12
- const nop = ( ) => { } ;
13
-
14
12
describe ( 'basic' , ( ) => {
15
13
it ( 'should correctly exec to a url' , async ( ) => {
16
14
const kc = new KubeConfig ( ) ;
@@ -27,27 +25,27 @@ describe('Exec', () => {
27
25
const path = `/api/v1/namespaces/${ namespace } /pods/${ pod } /exec` ;
28
26
29
27
await exec . exec (
30
- namespace , pod , container , cmd , osStream , errStream , isStream , nop , false ) ;
28
+ namespace , pod , container , cmd , osStream , errStream , isStream , false ) ;
31
29
let args = `stdout=true&stderr=true&stdin=true&tty=false&command=${ cmd } &container=${ container } ` ;
32
30
verify ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . called ( ) ;
33
31
34
32
await exec . exec (
35
- namespace , pod , container , cmd , null , errStream , isStream , nop , false ) ;
33
+ namespace , pod , container , cmd , null , errStream , isStream , false ) ;
36
34
args = `stdout=false&stderr=true&stdin=true&tty=false&command=${ cmd } &container=${ container } ` ;
37
35
verify ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . called ( ) ;
38
36
39
37
await exec . exec (
40
- namespace , pod , container , cmd , null , null , isStream , nop , false ) ;
38
+ namespace , pod , container , cmd , null , null , isStream , false ) ;
41
39
args = `stdout=false&stderr=false&stdin=true&tty=false&command=${ cmd } &container=${ container } ` ;
42
40
verify ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . called ( ) ;
43
41
44
42
await exec . exec (
45
- namespace , pod , container , cmd , null , null , null , nop , false ) ;
43
+ namespace , pod , container , cmd , null , null , null , false ) ;
46
44
args = `stdout=false&stderr=false&stdin=false&tty=false&command=${ cmd } &container=${ container } ` ;
47
45
verify ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . called ( ) ;
48
46
49
47
await exec . exec (
50
- namespace , pod , container , cmd , null , errStream , isStream , nop , true ) ;
48
+ namespace , pod , container , cmd , null , errStream , isStream , true ) ;
51
49
args = `stdout=false&stderr=true&stdin=true&tty=true&command=${ cmd } &container=${ container } ` ;
52
50
verify ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . called ( ) ;
53
51
} ) ;
@@ -68,11 +66,15 @@ describe('Exec', () => {
68
66
const path = `/api/v1/namespaces/${ namespace } /pods/${ pod } /exec` ;
69
67
const args = `stdout=true&stderr=true&stdin=true&tty=false&command=${ cmd } &container=${ container } ` ;
70
68
69
+ let statusOut = { } as V1Status ;
70
+
71
71
const fakeConn : WebSocket = mock ( WebSocket ) ;
72
72
when ( fakeWebSocket . connect ( `${ path } ?${ args } ` , null , anyFunction ( ) ) ) . thenResolve ( fakeConn ) ;
73
73
74
74
await exec . exec (
75
- namespace , pod , container , cmd , osStream , errStream , isStream , nop , false ) ;
75
+ namespace , pod , container , cmd , osStream , errStream , isStream , false , ( status : V1Status ) => {
76
+ statusOut = status ;
77
+ } ) ;
76
78
77
79
const [ , , outputFn ] = capture ( fakeWebSocket . connect ) . last ( ) ;
78
80
@@ -105,6 +107,14 @@ describe('Exec', () => {
105
107
isStream . put ( msg ) ;
106
108
verify ( fakeConn . send ( msg ) ) ;
107
109
110
+ const statusIn = {
111
+ code : 100 ,
112
+ message : 'this is a test' ,
113
+ } as V1Status ;
114
+
115
+ outputFn ( WebSocketHandler . StatusStream , Buffer . from ( JSON . stringify ( statusIn ) ) ) ;
116
+ expect ( statusOut ) . to . deep . equal ( statusIn ) ;
117
+
108
118
isStream . stop ( ) ;
109
119
verify ( fakeConn . close ( ) ) ;
110
120
} ) ;
0 commit comments