From 955ebfdf8dd0db049a94a93c456181bb8015c32a Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Wed, 13 May 2020 15:06:10 -0700 Subject: [PATCH] Update ow client (#162) * add header to invoke for extra logging * add test for X-OW-EXTRA-LOGGING, fix failing * update required openwhisk client for header addition --- package.json | 2 +- src/commands/runtime/action/invoke.js | 3 +- test/commands/runtime/action/invoke.test.js | 67 +++++++++++++-------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 4447d4ac..8767f83c 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "js-yaml": "^3.13.1", "lodash.clonedeep": "^4.5.0", "node-fetch": "^2.3.0", - "openwhisk": "^3.21.1", + "openwhisk": "^3.21.2", "openwhisk-fqn": "^0.0.2", "properties-reader": "2.0.0", "sha1": "^1.1.1" diff --git a/src/commands/runtime/action/invoke.js b/src/commands/runtime/action/invoke.js index 0a17f108..db8c10b4 100644 --- a/src/commands/runtime/action/invoke.js +++ b/src/commands/runtime/action/invoke.js @@ -32,7 +32,8 @@ class ActionInvoke extends RuntimeBaseCommand { name, params: paramsAction, blocking: flags.blocking || flags.result, - result: flags.result + result: flags.result, + headers: { 'X-OW-EXTRA-LOGGING': 'on' } }) this.logJSON('', result) } catch (err) { diff --git a/test/commands/runtime/action/invoke.test.js b/test/commands/runtime/action/invoke.test.js index b56ede6b..d5c47102 100644 --- a/test/commands/runtime/action/invoke.test.js +++ b/test/commands/runtime/action/invoke.test.js @@ -75,7 +75,24 @@ describe('instance methods', () => { command.argv = ['hello'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ name: 'hello', blocking: false, params: {}, result: false }) + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ + name: 'hello', + blocking: false, + params: {}, + result: false + })) + expect(stdout.output).toMatch('') + }) + }) + + test('sets X-OW-EXTRA-LOGGING header when invoking an action', () => { + const cmd = ow.mockResolved(owAction, '') + command.argv = ['hello'] + return command.run() + .then(() => { + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ + headers: expect.objectContaining({ 'X-OW-EXTRA-LOGGING': 'on' }) + })) expect(stdout.output).toMatch('') }) }) @@ -85,12 +102,12 @@ describe('instance methods', () => { command.argv = ['hello', '--param', 'a', 'b', 'c', 'd'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', params: { a: 'b', c: 'd' }, blocking: false, result: false - }) + })) expect(stdout.output).toMatch('') }) }) @@ -100,12 +117,12 @@ describe('instance methods', () => { command.argv = ['hello', '--param', 'a', 'b', '--param', 'c', 'd', '--blocking'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', params: { a: 'b', c: 'd' }, blocking: true, result: false - }) + })) expect(stdout.output).toMatch('') }) }) @@ -115,12 +132,12 @@ describe('instance methods', () => { command.argv = ['hello', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: true - }) + })) expect(stdout.output).toMatch('') }) }) @@ -131,12 +148,12 @@ describe('instance methods', () => { command.argv = ['hello'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: false, params: {}, result: false - }) + })) expect(stdout.output).toMatch(JSON.stringify(result, null, 2)) }) }) @@ -147,12 +164,12 @@ describe('instance methods', () => { command.argv = ['hello', '--blocking'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: false - }) + })) expect(stdout.output).toMatch(JSON.stringify(result, null, 2)) }) }) @@ -163,12 +180,12 @@ describe('instance methods', () => { command.argv = ['hello', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: true - }) + })) expect(stdout.output).toMatch(JSON.stringify(result, null, 2)) }) }) @@ -180,12 +197,12 @@ describe('instance methods', () => { command.argv = ['hello', '--blocking'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: false - }) + })) expect(stdout.output).toMatch(`activation took too long, use activation id 123456 to check for completion.`) }) @@ -198,12 +215,12 @@ describe('instance methods', () => { command.argv = ['hello', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: true - }) + })) expect(stdout.output).toMatch(`activation took too long, use activation id 123456 to check for completion.`) }) @@ -217,12 +234,12 @@ describe('instance methods', () => { command.argv = ['hello', '--blocking'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: false - }) + })) expect(stdout.output).toMatch(JSON.stringify(result, null, 2)) }) @@ -237,12 +254,12 @@ describe('instance methods', () => { command.argv = ['hello', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', blocking: true, params: {}, result: true - }) + })) expect(stdout.output).toMatch(JSON.stringify(result.response.result, null, 2)) }) @@ -253,12 +270,12 @@ describe('instance methods', () => { command.argv = ['hello', '--param', 'a', 'b', '--param', 'c', 'd', '--blocking', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', params: { a: 'b', c: 'd' }, blocking: true, result: true - }) + })) expect(stdout.output).toMatch('') }) }) @@ -274,12 +291,12 @@ describe('instance methods', () => { command.argv = ['hello', '--param-file', '/action/parameters.json', '--blocking', '--result'] return command.run() .then(() => { - expect(cmd).toHaveBeenCalledWith({ + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ name: 'hello', params: { param1: 'param1value', param2: 'param2value' }, blocking: true, result: true - }) + })) expect(stdout.output).toMatch('') }) })