Skip to content

Commit 0461710

Browse files
myan9starpit
authored andcommitted
fix(plugins/plugin-kubectl): kubectl api-resources table shows 'unknown' in title
Fixes #4145
1 parent f16df47 commit 0461710

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

plugins/plugin-kubectl/src/controller/kubectl/api-resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const doGet = (command: string) => async (args: Arguments<KubeOptions>):
3434
content: { stderr, stdout }
3535
} = response
3636

37-
const table = stringToTable(stdout, stderr, args, command, 'explain')
37+
const table = stringToTable(stdout, stderr, args, command, 'explain', 'api-resources')
3838

3939
if (isTable(table)) {
4040
table.body.forEach(_ => {

plugins/plugin-kubectl/src/lib/view/formatTable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const preprocessTable = (raw: string[]): Pair[][][] => {
145145

146146
/** normalize the status badge by capitalization */
147147
const capitalize = (str: string): string => {
148-
return !str ? 'Unknown' : str[0].toUpperCase() + str.slice(1).toLowerCase()
148+
return !str ? '' : str[0].toUpperCase() + str.slice(1).toLowerCase()
149149
}
150150

151151
/**
@@ -294,7 +294,7 @@ export const formatTable = <O extends KubeOptions>(
294294
((idx > 0 && cssForKey[key]) || '') +
295295
' ' +
296296
(cssForValue[column] || (key === 'READY' && cssForReadyCount(column)) || maybeRed(column)),
297-
value: key === 'STATUS' && idx > 0 ? capitalize(column) : column
297+
value: key === 'STATUS' && idx > 0 ? capitalize(column || 'unknown') : column
298298
})
299299
)
300300
.concat(fillTo(rows.length, maxColumns))

plugins/plugin-kubectl/src/test/k8s2/api-resources.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import { Common, CLI, Selectors, ReplExpect } from '@kui-shell/test'
1818
import { createNS, allocateNS, doHelp } from '../../../tests/lib/k8s/utils'
1919

20+
import * as assert from 'assert'
21+
2022
const commonModes = ['Introduction', 'Options']
2123
const kubectlApiResourcesModes = commonModes.concat(['api-resources'])
2224

@@ -29,7 +31,11 @@ describe('kubectl api-resources', function(this: Common.ISuite) {
2931

3032
it('should get a list of api resources', () =>
3133
CLI.command('kubectl api-resources', this.app)
32-
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME('bindings') }))
34+
.then(async res => {
35+
await ReplExpect.okWithCustom({ selector: Selectors.BY_NAME('bindings') })(res)
36+
const actualTitle = await this.app.client.getText(Selectors.TABLE_TITLE(res.count))
37+
assert.strictEqual(actualTitle, 'Api-resources')
38+
})
3339
.catch(Common.oops(this, true)))
3440

3541
it('should get a list of api resources', () =>

0 commit comments

Comments
 (0)