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

Commit 97ee5b7

Browse files
committed
add wsk activation get --last
Fixes #324
1 parent 305ca3e commit 97ee5b7

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

app/plugins/modules/composer/lib/await-app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ module.exports = (commandTree, prequire) => {
154154
return Promise.reject()
155155
}
156156

157+
if (arguments[arguments.length - 1].last) {
158+
//
159+
// the user has asked for wsk activation --last
160+
//
161+
const which = arguments[arguments.length - 1].last
162+
return repl.qexec(`wsk activation list --limit 1`
163+
+ (typeof which === 'string' ? ` --name ${which}` : ''))
164+
.then(activations => {
165+
if (activations.length === 0) {
166+
throw new Error('No such activation found')
167+
} else {
168+
return repl.qexec(`wsk activation get ${activations[0].activationId}`)
169+
}
170+
})
171+
}
172+
157173
return rawGet.apply(undefined, arguments)
158174
.then(response => {
159175
debug('response', response)

app/plugins/modules/composer/lib/usage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ exports.session_get = command => ({
137137
header: strings[`session_${command}`],
138138
example: `session ${command} <sessionId>`,
139139
oneof: [{ name: 'sessionId', docs: 'show a specific session id' },
140-
{ name: '--last', example: '[appName]', booleanOK: true, docs: 'show the last session [of the given app name]' },
140+
{ name: '--last', example: '[appName]', booleanOK: true, docs: 'show the last session [of the given app]' },
141141
{ name: '--last-failed', example: '[appName]', booleanOK: true, docs: 'ibid, except show the last failed session' }],
142142
optional: activationsUsage.get.optional,
143143
parents: ['composer', { command: 'composer session' }],

app/plugins/ui/commands/openwhisk-usage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ module.exports = {
344344
available: [{ command: 'get', fn: (command, syn='activation') => ({
345345
command, docs: 'get the full details of an activation', strict: command,
346346
example: `wsk ${syn} get <activationID>`,
347-
required: activationID,
347+
oneOf: [activationID,
348+
{ name: '--last [actionName]', booleanOK: true, docs: 'show the last activation [of the given action]' }],
348349
parents: [{ command: 'wsk' }, { command: 'wsk activation' }]
349350
})
350351
},
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2018 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
//
18+
// tests that create an action and test that it shows up in the list UI
19+
// this test also covers toggling the sidecar
20+
//
21+
const common = require('../../../lib/common'),
22+
openwhisk = require('../../../lib/openwhisk'),
23+
ui = require('../../../lib/ui'),
24+
assert = require('assert'),
25+
keys = ui.keys,
26+
cli = ui.cli,
27+
sidecar = ui.sidecar,
28+
actionName1 = `foo1-${new Date().getTime()}`,
29+
actionName2 = `foo2-${new Date().getTime()}`
30+
31+
describe('wsk activation get --last', function() {
32+
before(common.before(this))
33+
after(common.after(this))
34+
35+
it('should have an active repl', () => cli.waitForRepl(this.app))
36+
37+
// create an action
38+
it(`should create an action ${actionName1}`, () => cli.do(`create ${actionName1} ./data/foo.js`, this.app)
39+
.then(cli.expectOK)
40+
.then(sidecar.expectOpen)
41+
.then(sidecar.expectShowing(actionName1))
42+
.catch(common.oops(this)))
43+
44+
it(`should invoke it ${actionName1}`, () => cli.do(`invoke -p name lastTestIPromise`, this.app)
45+
.then(cli.expectOK)
46+
.then(sidecar.expectOpen)
47+
.then(sidecar.expectShowing(actionName1))
48+
.catch(common.oops(this)))
49+
50+
// create another action
51+
it(`should create an action ${actionName2}`, () => cli.do(`create ${actionName2} ./data/foo.js`, this.app)
52+
.then(cli.expectOK)
53+
.then(sidecar.expectOpen)
54+
.then(sidecar.expectShowing(actionName2))
55+
.catch(common.oops(this)))
56+
57+
it(`should show ${actionName1} with wsk activation get --last`, () => this.app.client.waitUntil(() => {
58+
return cli.do(`wsk activation get --last`, this.app)
59+
.then(cli.expectOK)
60+
.then(sidecar.expectOpen)
61+
.then(sidecar.expectShowing(actionName1, undefined, undefined, undefined, undefined, 500))
62+
.then(() => this.app.client.getText(ui.selectors.SIDECAR_ACTIVATION_RESULT))
63+
.then(ui.expectStruct({name:'Step1 lastTestIPromise'}))
64+
.catch(common.oops(this))
65+
}))
66+
67+
it(`should invoke it ${actionName2}`, () => cli.do(`invoke ${actionName2} -p name lastTestIPromise`, this.app)
68+
.then(cli.expectOK)
69+
.then(sidecar.expectOpen)
70+
.then(sidecar.expectShowing(actionName2))
71+
.catch(common.oops(this)))
72+
73+
it(`should show ${actionName1} with wsk activation get --last ${actionName1}`, () => this.app.client.waitUntil(() => {
74+
return cli.do(`wsk activation get --last ${actionName1}`, this.app)
75+
.then(cli.expectOK)
76+
.then(sidecar.expectOpen)
77+
.then(sidecar.expectShowing(actionName1, undefined, undefined, undefined, undefined, 500))
78+
.then(() => this.app.client.getText(ui.selectors.SIDECAR_ACTIVATION_RESULT))
79+
.then(ui.expectStruct({name:'Step1 lastTestIPromise'}))
80+
.catch(common.oops(this))
81+
}))
82+
83+
it(`should show ${actionName2} with wsk activation get --last ${actionName2}`, () => this.app.client.waitUntil(() => {
84+
return cli.do(`wsk activation get --last ${actionName2}`, this.app)
85+
.then(cli.expectOK)
86+
.then(sidecar.expectOpen)
87+
.then(sidecar.expectShowing(actionName2, undefined, undefined, undefined, undefined, 500))
88+
.then(() => this.app.client.getText(ui.selectors.SIDECAR_ACTIVATION_RESULT))
89+
.then(ui.expectStruct({name:'Step1 lastTestIPromise'}))
90+
.catch(common.oops(this))
91+
}))
92+
})

0 commit comments

Comments
 (0)