This is an automated email from the ASF dual-hosted git repository. jamesthomas pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-js.git
The following commit(s) were added to refs/heads/master by this push: new 79d6c02 Test case and fix for #121 (#122) 79d6c02 is described below commit 79d6c022a6fc6914a56b44f237dd133d3c137a00 Author: Lars Trieloff <l...@trieloff.net> AuthorDate: Wed Jul 11 15:29:25 2018 +0200 Test case and fix for #121 (#122) * Simple fix and tests for apache/incubator-openwhisk-client-js#121 - if an `options.exec` object is provided, use it - override derived or inferred values in `body.exec` in the process --- lib/actions.js | 5 +++++ test/unit/actions.test.js | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lib/actions.js b/lib/actions.js index 06f205d..58ee064 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -50,6 +50,11 @@ class Actions extends Resources { } const body = {exec: {kind: options.kind || 'nodejs:default', code: options.action}} + // allow options to override the derived exec object + if (options.exec) { + body.exec = Object.assign(body.exec, options.exec) + } + if (options.action instanceof Buffer) { body.exec.code = options.action.toString('base64') } else if (typeof options.action === 'object') { diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js index c3a6455..4873d32 100644 --- a/test/unit/actions.test.js +++ b/test/unit/actions.test.js @@ -444,3 +444,51 @@ test('should pass through requested User-Agent header', t => { return actions.create({name: '12345', action, version, 'User-Agent': userAgent}) }) + +test('should pass through exec.image parameter', t => { + t.plan(1) + const image = 'openwhisk/action-nodejs-v8:latest' + const exec = { image: image } + const client = {} + const actions = new Actions(client) + const action = 'function main() { // main function body};' + const version = '1.0.0' + + client.request = (method, path, options) => { + t.is(options.body.exec.image, image) + } + + return actions.create({name: '12345', action, version, exec, kind: 'blackbox'}) +}) + +test('should pass through exec.image parameter (for all kinds)', t => { + t.plan(1) + const image = 'openwhisk/action-nodejs-v8:latest' + const exec = { image: image } + const client = {} + const actions = new Actions(client) + const action = 'function main() { // main function body};' + const version = '1.0.0' + + client.request = (method, path, options) => { + t.is(options.body.exec.image, image) + } + + return actions.create({name: '12345', action, version, exec, kind: 'xyz'}) +}) + +test('should not reset kind parameter when passing through exec.image parameter', t => { + t.plan(1) + const image = 'openwhisk/action-nodejs-v8:latest' + const exec = { image: image } + const client = {} + const actions = new Actions(client) + const action = 'function main() { // main function body};' + const version = '1.0.0' + + client.request = (method, path, options) => { + t.is(options.body.exec.kind, 'xyz') + } + + return actions.create({name: '12345', action, version, exec, kind: 'xyz'}) +})