Skip to content

Commit

Permalink
test: kubectl logs tests were broken by nginx 1.19 release
Browse files Browse the repository at this point in the history
Fixes #4799
  • Loading branch information
myan9 authored and starpit committed Jun 6, 2020
1 parent 76fb3d3 commit adee7d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
37 changes: 23 additions & 14 deletions plugins/plugin-kubectl/logs/src/test/logs/logs-dash-c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import {
import { readFileSync } from 'fs'
import { dirname, join } from 'path'
const ROOT = dirname(require.resolve('@kui-shell/plugin-kubectl/tests/package.json'))
const inputBuffer = readFileSync(join(ROOT, 'data/k8s/kubectl-logs-two-containers.yaml'))
const inputEncoded = inputBuffer.toString('base64')
const inputBuffer1 = readFileSync(join(ROOT, 'data/k8s/kubectl-logs-two-containers.yaml'))
const inputEncoded1 = inputBuffer1.toString('base64')
const inputBuffer2 = readFileSync(join(ROOT, 'data/k8s/bunch/pod.yaml'))
const inputEncoded2 = inputBuffer2.toString('base64')

const sleepTime = 3

Expand All @@ -49,20 +51,21 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
const ns: string = createNS()
allocateNS(this, ns)

const podName = 'kui-two-containers'
const podName1 = 'kui-two-containers'
const allContainers = 'All Containers'
const containerName1 = 'nginx'
const containerName2 = 'vim'
const podName2 = 'nginx'

const createPodWithoutWaiting = () => {
const createPodWithoutWaiting = (inputEncoded: string, podName: string) => {
it(`should create sample pod from URL`, () => {
return CLI.command(`echo ${inputEncoded} | base64 --decode | kubectl create -f - -n ${ns}`, this.app)
.then(ReplExpect.okWithPtyOutput(podName))
.catch(Common.oops(this, true))
})
}

const waitForPod = () => {
const waitForPod = (podName: string) => {
it(`should wait for the pod to come up`, () => {
return CLI.command(`kubectl get pod ${podName} -n ${ns} -w`, this.app)
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(podName) }))
Expand All @@ -71,7 +74,7 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
})
}

const getPodViaClick = (wait = true) => {
const getPodViaClick = (podName: string, wait = true) => {
it(`should get pods via kubectl then click`, async () => {
try {
const selector: string = await CLI.command(`kubectl get pods ${podName} -n ${ns}`, this.app).then(
Expand All @@ -94,7 +97,7 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
})
}

const getPodViaYaml = () => {
const getPodViaYaml = (podName: string) => {
it('should get pods via kubectl get -o yaml', async () => {
try {
await CLI.command(`kubectl get pods ${podName} -n ${ns} -o yaml`, this.app)
Expand Down Expand Up @@ -202,9 +205,15 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
}

/* Here comes the test */
createPodWithoutWaiting()
waitForPod()
getPodViaClick()

createPodWithoutWaiting(inputEncoded2, podName2)
waitForPod(podName2)
getPodViaClick(podName2)
switchToLogsTab(['No log data'], { text: 'Logs are live', type: 'info' })

createPodWithoutWaiting(inputEncoded1, podName1)
waitForPod(podName1)
getPodViaClick(podName1)
switchToLogsTab([containerName1, containerName2], { text: 'Logs are live', type: 'info' })

/** testing various combination here */
Expand Down Expand Up @@ -243,7 +252,7 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
type: 'info'
})

deletePodByName(this, podName, ns)
deletePodByName(this, podName1, ns)

it('should see log streaming stopped', async () => {
try {
Expand Down Expand Up @@ -279,15 +288,15 @@ wdescribe(`kubectl Logs tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
type: 'error'
})

createPodWithoutWaiting() // recreate this pod
getPodViaYaml() // NOTE: immediately open sidecar when pod is in creation
createPodWithoutWaiting(inputEncoded1, podName1) // recreate this pod
getPodViaYaml(podName1) // NOTE: immediately open sidecar when pod is in creation

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

waitForPod() // wait for pod ready
waitForPod(podName1) // wait for pod ready

doRetry([containerName1, containerName2], {
text: 'Logs are live',
Expand Down
17 changes: 0 additions & 17 deletions plugins/plugin-kubectl/src/test/k8s2/get-pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ commands.forEach(command => {
assert.ok(!/Initializing/i.test(message))
} */

const testLogsTab = async (click = true) => {
if (click) {
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON('logs'))
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON('logs'))
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON_SELECTED('logs'))
}

await SidecarExpect.toolbarText({ type: 'info', text: 'Logs are live', exact: false })(this.app)

return this.app.client.waitUntil(async () => {
const text = await this.app.client.getText(`${Selectors.SIDECAR} .kui--sidecar-text-content`)
return text === 'No log data'
})
}

const ns: string = createNS()
const inNamespace = `-n ${ns}`
allocateNS(this, ns)
Expand Down Expand Up @@ -283,8 +268,6 @@ commands.forEach(command => {
}
})

it('should show logs tab', testLogsTab)

it('should click on the sidecar maximize button', async () => {
try {
await this.app.client.click(Selectors.SIDECAR_MAXIMIZE_BUTTON)
Expand Down
3 changes: 2 additions & 1 deletion plugins/plugin-kubectl/tests/data/k8s/bunch/pod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copy of pod.yaml without file extension for test
# use nginx version 1.18: see https://github.com/IBM/kui/issues/4799
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -8,6 +9,6 @@ metadata:
spec:
containers:
- name: nginx
image: nginx
image: nginx:1.18.0
ports:
- containerPort: 80

0 comments on commit adee7d5

Please sign in to comment.