@@ -58,57 +58,105 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
58
58
const containerName1 = 'nginx'
59
59
const containerName2 = 'vim'
60
60
61
- it ( `should create sample pod from URL` , ( ) => {
62
- return CLI . command ( `echo ${ inputEncoded } | base64 --decode | kubectl create -f - -n ${ ns } ` , this . app )
63
- . then ( ReplExpect . okWithPtyOutput ( podName ) )
64
- . catch ( Common . oops ( this , true ) )
65
- } )
61
+ const createPodWithoutWaiting = ( ) => {
62
+ it ( `should create sample pod from URL` , ( ) => {
63
+ return CLI . command ( `echo ${ inputEncoded } | base64 --decode | kubectl create -f - -n ${ ns } ` , this . app )
64
+ . then ( ReplExpect . okWithPtyOutput ( podName ) )
65
+ . catch ( Common . oops ( this , true ) )
66
+ } )
67
+ }
66
68
67
- it ( `should wait for the pod to come up` , ( ) => {
68
- return CLI . command ( `kubectl get pod ${ podName } -n ${ ns } -w` , this . app )
69
- . then ( ReplExpect . okWithCustom ( { selector : Selectors . BY_NAME ( podName ) } ) )
70
- . then ( selector => waitForGreen ( this . app , selector ) )
71
- . catch ( Common . oops ( this , true ) )
72
- } )
69
+ const waitForPod = ( ) => {
70
+ it ( `should wait for the pod to come up` , ( ) => {
71
+ return CLI . command ( `kubectl get pod ${ podName } -n ${ ns } -w` , this . app )
72
+ . then ( ReplExpect . okWithCustom ( { selector : Selectors . BY_NAME ( podName ) } ) )
73
+ . then ( selector => waitForGreen ( this . app , selector ) )
74
+ . catch ( Common . oops ( this , true ) )
75
+ } )
76
+ }
73
77
74
- it ( `should get pods via kubectl then click` , async ( ) => {
75
- try {
76
- const selector : string = await CLI . command ( `kubectl get pods ${ podName } -n ${ ns } ` , this . app ) . then (
77
- ReplExpect . okWithCustom ( { selector : Selectors . BY_NAME ( podName ) } )
78
- )
79
-
80
- // wait for the badge to become green
81
- await waitForGreen ( this . app , selector )
82
-
83
- // now click on the table row
84
- await this . app . client . click ( `${ selector } .clickable` )
85
- await SidecarExpect . open ( this . app )
86
- . then ( SidecarExpect . mode ( defaultModeForGet ) )
87
- . then ( SidecarExpect . showing ( podName ) )
88
- } catch ( err ) {
89
- return Common . oops ( this , true ) ( err )
90
- }
91
- } )
78
+ const getPodViaClick = ( wait = true ) => {
79
+ it ( `should get pods via kubectl then click` , async ( ) => {
80
+ try {
81
+ const selector : string = await CLI . command ( `kubectl get pods ${ podName } -n ${ ns } ` , this . app ) . then (
82
+ ReplExpect . okWithCustom ( { selector : Selectors . BY_NAME ( podName ) } )
83
+ )
92
84
93
- it ( 'should show logs tab' , async ( ) => {
94
- try {
95
- await this . app . client . waitForVisible ( Selectors . SIDECAR_MODE_BUTTON ( 'logs' ) )
96
- await this . app . client . click ( Selectors . SIDECAR_MODE_BUTTON ( 'logs' ) )
97
- await this . app . client . waitForVisible ( Selectors . SIDECAR_MODE_BUTTON_SELECTED ( 'logs' ) )
85
+ if ( wait ) {
86
+ // wait for the badge to become green
87
+ await waitForGreen ( this . app , selector )
88
+ }
98
89
99
- await SidecarExpect . toolbarText ( { type : 'info' , text : 'Logs are live' , exact : false } ) ( this . app )
90
+ // now click on the table row
91
+ await this . app . client . click ( `${ selector } .clickable` )
92
+ await SidecarExpect . open ( this . app )
93
+ . then ( SidecarExpect . mode ( defaultModeForGet ) )
94
+ . then ( SidecarExpect . showing ( podName ) )
95
+ } catch ( err ) {
96
+ return Common . oops ( this , true ) ( err )
97
+ }
98
+ } )
99
+ }
100
100
101
- await sleep ( sleepTime )
102
- await waitForLogText ( ( text : string ) => text . includes ( containerName1 ) && text . includes ( containerName2 ) )
103
- } catch ( err ) {
104
- return Common . oops ( this , true ) ( err )
101
+ const getPodViaYaml = ( ) => {
102
+ it ( 'should get pods via kubectl get -o yaml' , async ( ) => {
103
+ try {
104
+ await CLI . command ( `kubectl get pods ${ podName } -n ${ ns } -o yaml` , this . app )
105
+ await SidecarExpect . open ( this . app )
106
+ } catch ( err ) {
107
+ return Common . oops ( this , true ) ( err )
108
+ }
109
+ } )
110
+ }
111
+
112
+ const testLogsContent = ( show : string [ ] , notShow ?: string [ ] ) => {
113
+ if ( show ) {
114
+ show . forEach ( showInLog => {
115
+ it ( `should show ${ showInLog } in log output` , async ( ) => {
116
+ try {
117
+ await sleep ( sleepTime )
118
+ await waitForLogText ( ( text : string ) => text . indexOf ( showInLog ) !== - 1 )
119
+ } catch ( err ) {
120
+ return Common . oops ( this , true ) ( err )
121
+ }
122
+ } )
123
+ } )
105
124
}
106
- } )
125
+
126
+ if ( notShow ) {
127
+ notShow . forEach ( notShowInLog => {
128
+ it ( `should not show ${ notShowInLog } in log output` , async ( ) => {
129
+ try {
130
+ await sleep ( sleepTime )
131
+ await waitForLogText ( ( text : string ) => text . indexOf ( notShowInLog ) === - 1 )
132
+ } catch ( err ) {
133
+ return Common . oops ( this , true ) ( err )
134
+ }
135
+ } )
136
+ } )
137
+ }
138
+ }
139
+
140
+ const switchToLogsTab = ( showInLog : string [ ] , toolbar : { text : string ; type : string } ) => {
141
+ it ( 'should show logs tab' , async ( ) => {
142
+ try {
143
+ await this . app . client . waitForVisible ( Selectors . SIDECAR_MODE_BUTTON ( 'logs' ) )
144
+ await this . app . client . click ( Selectors . SIDECAR_MODE_BUTTON ( 'logs' ) )
145
+ await this . app . client . waitForVisible ( Selectors . SIDECAR_MODE_BUTTON_SELECTED ( 'logs' ) )
146
+
147
+ await SidecarExpect . toolbarText ( { type : toolbar . type , text : toolbar . text , exact : false } ) ( this . app )
148
+
149
+ testLogsContent ( showInLog )
150
+ } catch ( err ) {
151
+ return Common . oops ( this , true ) ( err )
152
+ }
153
+ } )
154
+ }
107
155
108
156
const switchContainer = (
109
157
container : string ,
110
- _showInLog : string [ ] ,
111
- _notShowInLog : string [ ] ,
158
+ showInLog : string [ ] ,
159
+ notShowInLog : string [ ] ,
112
160
toolbar : { text : string ; type : string }
113
161
) => {
114
162
it ( `should switch to container ${ container } ` , async ( ) => {
@@ -124,27 +172,7 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
124
172
}
125
173
} )
126
174
127
- _showInLog . forEach ( showInLog => {
128
- it ( `should show ${ showInLog } in log output` , async ( ) => {
129
- try {
130
- await sleep ( sleepTime )
131
- await waitForLogText ( ( text : string ) => text . indexOf ( showInLog ) !== - 1 )
132
- } catch ( err ) {
133
- return Common . oops ( this , true ) ( err )
134
- }
135
- } )
136
- } )
137
-
138
- _notShowInLog . forEach ( notShowInLog => {
139
- it ( `should not show ${ notShowInLog } in log output` , async ( ) => {
140
- try {
141
- await sleep ( sleepTime )
142
- await waitForLogText ( ( text : string ) => text . indexOf ( notShowInLog ) === - 1 )
143
- } catch ( err ) {
144
- return Common . oops ( this , true ) ( err )
145
- }
146
- } )
147
- } )
175
+ testLogsContent ( showInLog , notShowInLog )
148
176
}
149
177
150
178
const toggleStreaming = ( changeToLive : boolean ) => {
@@ -164,6 +192,25 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
164
192
} )
165
193
}
166
194
195
+ const doRetry = ( showInLog : string [ ] , toolbar : { text : string ; type : string } ) => {
196
+ it ( 'should hit retry' , async ( ) => {
197
+ try {
198
+ await this . app . client . waitForVisible ( Selectors . SIDECAR_MODE_BUTTON ( 'retry-streaming' ) )
199
+ await this . app . client . click ( Selectors . SIDECAR_MODE_BUTTON ( 'retry-streaming' ) )
200
+ await SidecarExpect . toolbarText ( { text : toolbar . text , type : toolbar . type , exact : false } ) ( this . app )
201
+ testLogsContent ( showInLog )
202
+ } catch ( err ) {
203
+ return Common . oops ( this , true ) ( err )
204
+ }
205
+ } )
206
+ }
207
+
208
+ /* Here comes the test */
209
+ createPodWithoutWaiting ( )
210
+ waitForPod ( )
211
+ getPodViaClick ( )
212
+ switchToLogsTab ( [ containerName1 , containerName2 ] , { text : 'Logs are live' , type : 'info' } )
213
+
167
214
/** testing various combination here */
168
215
switchContainer ( containerName1 , [ containerName1 ] , [ containerName2 ] , { text : containerName1 , type : 'info' } )
169
216
@@ -237,5 +284,25 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
237
284
type : 'error'
238
285
} )
239
286
287
+ doRetry ( [ 'not found' ] , {
288
+ text : showError ,
289
+ type : 'error'
290
+ } )
291
+
292
+ createPodWithoutWaiting ( ) // recreate this pod
293
+ getPodViaYaml ( ) // NOTE: immediately open sidecar when pod is in creation
294
+
295
+ switchToLogsTab ( [ 'not found' ] , {
296
+ text : showError ,
297
+ type : 'error'
298
+ } )
299
+
300
+ waitForPod ( ) // wait for pod ready
301
+
302
+ doRetry ( [ containerName1 , containerName2 ] , {
303
+ text : 'Logs are live' ,
304
+ type : 'info'
305
+ } )
306
+
240
307
deleteNS ( this , ns )
241
308
} )
0 commit comments