Skip to content

Commit

Permalink
Update ow client (#162)
Browse files Browse the repository at this point in the history
* add header to invoke for extra logging
* add test for X-OW-EXTRA-LOGGING, fix failing
* update required openwhisk client for header addition
  • Loading branch information
purplecabbage authored May 13, 2020
1 parent 41713e2 commit 955ebfd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/runtime/action/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
67 changes: 42 additions & 25 deletions test/commands/runtime/action/invoke.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
})
})
Expand All @@ -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('')
})
})
Expand All @@ -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('')
})
})
Expand All @@ -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('')
})
})
Expand All @@ -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))
})
})
Expand All @@ -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))
})
})
Expand All @@ -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))
})
})
Expand All @@ -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.`)
})
Expand All @@ -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.`)
})
Expand All @@ -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))
})
Expand All @@ -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))
})
Expand All @@ -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('')
})
})
Expand All @@ -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('')
})
})
Expand Down

0 comments on commit 955ebfd

Please sign in to comment.