Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 05ec689

Browse files
committed
improve error handling when user requests params for activation
Fixes #538
1 parent 84202e9 commit 05ec689

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

app/plugins/views/sidecar/mode.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ module.exports = (commandTree, require) => {
4747
if (sidecar && sidecar.entity && (!entityType
4848
|| sidecar.entity.type === entityType
4949
|| util.isArray(entityType) && entityType.find(t => t === sidecar.entity.type))) {
50-
sidecarVisibility.show()
51-
return ui.showEntity(sidecar.entity, { show: mode }, block, nextBlock)
50+
if (mode !== 'raw' &&
51+
!(sidecar.entity[mode]
52+
|| (sidecar.entity.exec && sidecar.entity.exec[mode])
53+
|| (sidecar.entity.response && sidecar.entity.response[mode]))) {
54+
throw new Error(`The current entity does not support viewing ${mode}`)
55+
} else {
56+
sidecarVisibility.show()
57+
return ui.showEntity(sidecar.entity, { show: mode }, block, nextBlock)
58+
}
5259
} else {
5360
throw new Error(!entityType ? 'You have not selected an entity'
5461
: `You have not yet selected ${ui.startsWithVowel(entityType) ? 'an' : 'a'} ${entityType.replace(/s$/, '')}`)

tests/lib/ui.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,24 @@ exports.sidecar.expectRule = A => app => app.client.waitUntil(() => {
279279
})
280280

281281
/** is the given struct2 the same as the given struct2 (given as a string) */
282-
exports.expectStruct = (struct1, noParse=false) => string => {
282+
exports.expectStruct = (struct1, noParse=false, failFast=true) => string => {
283283
try {
284-
assert.ok(sameStruct(struct1, noParse ? string : JSON.parse(string)))
285-
return true
284+
const ok = sameStruct(struct1, noParse ? string : JSON.parse(string))
285+
if (failFast) {
286+
assert.ok(ok)
287+
}
288+
return ok
286289
} catch (err) {
287290
console.error('Error comparing structs for actual value= ' + string)
288291
throw err
289292
}
290293
}
291-
exports.expectSubset = struct1 => string => {
294+
exports.expectSubset = (struct1, failFast=true) => string => {
292295
try {
293-
assert.ok(sameStruct(struct1, JSON.parse(string), true))
296+
const ok = sameStruct(struct1, JSON.parse(string), true)
297+
if (failFast) {
298+
assert.ok(ok)
299+
}
294300
return true
295301
} catch (err) {
296302
console.error('Error comparing subset for actual value= ' + string)

tests/tests/passes/03/bottom-stripe-activation.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,34 @@ describe('Sidecar bottom stripe interactions for activations', function() {
5050
})
5151
.catch(common.oops(this)))
5252

53+
// this will form a part of the annotations record
54+
const subsetOfAnnotations = {path: `${ui.expectedNamespace()}/${name}`}
55+
5356
it(`should show annotations for ${name} by clicking on bottom stripe`, () => this.app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('annotations'))
5457
.then(() => this.app)
5558
.then(sidecar.expectOpen)
5659
.then(sidecar.expectShowing(name))
5760
.then(app => app.client.getText(`${ui.selectors.SIDECAR_CONTENT} .activation-result`))
58-
.then(ui.expectSubset({path: `${ui.expectedNamespace()}/${name}`}))
61+
.then(ui.expectSubset(subsetOfAnnotations))
5962
.catch(common.oops(this)))
6063

61-
// click on annotations mode button
64+
// click on result mode button
6265
it(`should show result for ${name} by clicking on bottom stripe`, () => this.app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('result'))
6366
.then(() => this.app)
6467
.then(sidecar.expectOpen)
6568
.then(sidecar.expectShowing(name))
6669
.then(app => app.client.getText(`${ui.selectors.SIDECAR_CONTENT} .activation-result`))
6770
.then(ui.expectStruct(expectedResult))
6871
.catch(common.oops(this)))
72+
73+
// click on raw mode button
74+
it(`should show raw for ${name} by clicking on bottom stripe`, () => this.app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('raw'))
75+
.then(() => this.app)
76+
.then(sidecar.expectOpen)
77+
.then(sidecar.expectShowing(name))
78+
.then(app => app.client.getText(`${ui.selectors.SIDECAR_CONTENT} .activation-result`))
79+
.then(ui.expectSubset({ name, namespace: ui.expectedNamespace() })) // parts of the raw annotation record
80+
.catch(common.oops(this)))
6981
}
7082

7183
it('should have an active repl', () => cli.waitForRepl(this.app))

tests/tests/passes/03/invoke-implicit.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ describe('wsk action invoke with implicit entity', function() {
4545
.then(ui.expectStruct({ x:3, name:'grumble' }))
4646
.catch(common.oops(this)))
4747
}
48+
49+
it(`should fail when requesting parameters of an activation`, () => cli.do('params', this.app)
50+
.then(cli.expectError(0, 'The current entity does not support viewing parameters'))
51+
.catch(common.oops(this)))
4852
})

0 commit comments

Comments
 (0)