Skip to content

Commit

Permalink
fix: the Logs/Terminal retry button should be visible on any exit code
Browse files Browse the repository at this point in the history
Fixes #4769
  • Loading branch information
myan9 authored and starpit committed May 29, 2020
1 parent be04d20 commit 3366327
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 21 deletions.
17 changes: 9 additions & 8 deletions plugins/plugin-kubectl/logs/src/test/logs/logs-dash-c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
allocateNS,
deleteNS,
waitForGreen,
waitForRed,
waitForTerminalText,
defaultModeForGet
defaultModeForGet,
deletePodByName
} from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils'

import { readFileSync } from 'fs'
Expand Down Expand Up @@ -243,12 +243,7 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
type: 'info'
})

it(`should delete the pod ${podName} by name via kubectl`, () => {
return CLI.command(`kubectl delete pod ${podName} -n ${ns}`, this.app)
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(podName) }))
.then(selector => waitForRed(this.app, selector))
.catch(Common.oops(this, true))
})
deletePodByName(this, podName, ns)

it('should see log streaming stopped', async () => {
try {
Expand All @@ -260,6 +255,12 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
})

const showError = 'Log streaming stopped abnormally.'

doRetry(['not found'], {
text: showError,
type: 'error'
})

switchContainer(containerName1, ['not found'], [], {
text: showError,
type: 'error'
Expand Down
16 changes: 16 additions & 0 deletions plugins/plugin-kubectl/logs/src/test/logs/logs-via-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ wdescribe(`kubectl logs getty via table ${process.env.MOCHA_RUN_TARGET || ''}`,
}
}

const doRetry = (hasLogs: boolean) => {
it('should click retry button', async () => {
try {
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))

if (hasLogs) {
await waitForLogText('hi')
}
} catch (err) {
return Common.oops(this, true)(err)
}
})
}

allocateNS(this, ns)
inputs.forEach(_ => {
if (_.expectString) {
Expand All @@ -114,6 +129,7 @@ wdescribe(`kubectl logs getty via table ${process.env.MOCHA_RUN_TARGET || ''}`,
}
waitForPod(_.podName)
showLogs(_.podName, _.containerName, _.label, _.hasLogs)
doRetry(_.hasLogs)
})
inputs.forEach(_ => {
showLogs(_.podName, _.containerName, _.label, _.hasLogs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export abstract class ContainerComponent<State extends ContainerState> extends R
protected abstract toolbarText(status: StreamingStatus): ToolbarText

protected toolbarButtonsForError(status: StreamingStatus): Button[] {
if (status === 'Error') {
if (status === 'Stopped' || status === 'Error') {
return [
{
mode: 'retry-streaming',
Expand Down
33 changes: 21 additions & 12 deletions plugins/plugin-kubectl/src/test/k8s2/terminal-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
createNS,
allocateNS,
deleteNS,
deletePodByName,
waitForGreen,
getTerminalText,
waitForTerminalText,
Expand Down Expand Up @@ -103,6 +104,18 @@ describe(`${command} Terminal tab ${process.env.MOCHA_RUN_TARGET || ''}`, functi
})
}

const doRetry = (toolbar: { type: string; text: string; exact: boolean }) => {
it('should click retry button', async () => {
try {
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))
await SidecarExpect.toolbarText(toolbar)(this.app)
} catch (err) {
return Common.oops(this, true)(err)
}
})
}

/** switch to terminal tab, exit with 1, see error in toolbar and click retry button */
const exitTerminalTabAndRetry = () => {
it('should show terminal tab and exit with error', async () => {
Expand All @@ -127,18 +140,10 @@ describe(`${command} Terminal tab ${process.env.MOCHA_RUN_TARGET || ''}`, functi
}
})

it('should click retry button', async () => {
try {
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON('retry-streaming'))
await SidecarExpect.toolbarText({
type: 'info',
text: `Connected to container ${containerName}`,
exact: false
})(this.app)
} catch (err) {
return Common.oops(this, true)(err)
}
doRetry({
type: 'info',
text: `Connected to container ${containerName}`,
exact: false
})
}

Expand Down Expand Up @@ -212,5 +217,9 @@ describe(`${command} Terminal tab ${process.env.MOCHA_RUN_TARGET || ''}`, functi
}
})

deletePodByName(this, podName, ns)

doRetry({ type: 'error', text: 'has closed', exact: false })

deleteNS(this, ns)
})
7 changes: 7 additions & 0 deletions plugins/plugin-kubectl/tests/lib/k8s/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ declare function allocateNS (ctx: Common.ISuite, ns: string, command?: string, t
*/
declare function deleteNS (ctx: Common.ISuite, ns: string, command?: string, theCli?: headless): void

/**
* Install a mocha test to delete the given pod by name `pod`
*
*/
declare function deletePodByName (ctx: Common.ISuite, pod: string, ns: string, command?: string, theCli?: headless): void


/**
* Keep poking the given kind till no more such entities exist
*
Expand Down
10 changes: 10 additions & 0 deletions plugins/plugin-kubectl/tests/lib/k8s/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ exports.deleteNS = (ctx, ns, command = 'kubectl', theCli = CLI) => {
}
}

exports.deletePodByName = (ctx, pod, ns, command = 'kubectl', theCli = CLI) => {
it(`should delete the pod ${pod} by name via ${command}`, () => {
return theCli
.command(`kubectl delete pod ${pod} -n ${ns}`, ctx.app)
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(pod) }))
.then(selector => exports.waitForRed(ctx.app, selector))
.catch(Common.oops(ctx, true))
})
}

/**
* Keep poking the given kind till no more such entities exist
*
Expand Down

0 comments on commit 3366327

Please sign in to comment.