|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +const chalk = require('chalk'); |
3 | 4 | const expect = require('chai').expect;
|
4 | 5 | const chaiAsPromised = require('chai-as-promised');
|
5 | 6 | const sinon = require('sinon');
|
@@ -217,4 +218,84 @@ describe('OpenWhiskInvoke', () => {
|
217 | 218 | return expect(openwhiskInvoke.invoke()).to.be.eventually.rejected;
|
218 | 219 | });
|
219 | 220 | });
|
| 221 | + |
| 222 | + describe('#log()', () => { |
| 223 | + it('should log activation response result', () => { |
| 224 | + const log = sandbox.stub(openwhiskInvoke, 'consoleLog'); |
| 225 | + openwhiskInvoke.options.log = 'result' |
| 226 | + openwhiskInvoke.options.type = 'blocking' |
| 227 | + |
| 228 | + const result = {success: true, result: { hello: "world"} }; |
| 229 | + return openwhiskInvoke.log({response: result}).then(() => { |
| 230 | + expect(log.calledOnce).to.be.equal(true); |
| 231 | + const msg = chalk.white(JSON.stringify(result.result, null, 4)); |
| 232 | + console.log(msg) |
| 233 | + expect(log.args[0][0]).to.be.equal(msg); |
| 234 | + }); |
| 235 | + }); |
| 236 | + |
| 237 | + it('should log verbose activation response result', () => { |
| 238 | + const log = sandbox.stub(openwhiskInvoke, 'consoleLog'); |
| 239 | + openwhiskInvoke.options.log = 'result' |
| 240 | + openwhiskInvoke.options.type = 'blocking' |
| 241 | + openwhiskInvoke.options.v = true |
| 242 | + |
| 243 | + const input = { |
| 244 | + activationId: 12345, |
| 245 | + name: 'blah', |
| 246 | + namespace: 'workspace', |
| 247 | + duration: 100, |
| 248 | + annotations: [ { key: "waitTime", value: 33 } ], |
| 249 | + response: { success: true, result: { hello: "world"} } |
| 250 | + }; |
| 251 | + return openwhiskInvoke.log(input).then(() => { |
| 252 | + expect(log.calledTwice).to.be.equal(true); |
| 253 | + const msg = chalk.white(JSON.stringify(input.response.result, null, 4)); |
| 254 | + |
| 255 | + const field = (name, label) => `${chalk.blue(name)} (${chalk.yellow(label)})` |
| 256 | + const time = (name, value, color = 'blue') => `${chalk[color](name)}: ${chalk.green(value + 'ms')}` |
| 257 | + const duration = (duration, init = 0, wait) => `${time('duration', duration)} (${time('init', init, 'magenta')}, ${time('wait', wait, 'magenta')})` |
| 258 | + |
| 259 | + const output = `${chalk.green('=>')} ${field('action', '/workspace/blah')} ${field('activation', 12345)} ${duration(100, undefined, 33)}` |
| 260 | + |
| 261 | + expect(log.args[0][0]).to.be.equal(output); |
| 262 | + expect(log.args[1][0]).to.be.equal(msg); |
| 263 | + }); |
| 264 | + }); |
| 265 | + |
| 266 | + it('should log verbose activation coldstart response result', () => { |
| 267 | + const log = sandbox.stub(openwhiskInvoke, 'consoleLog'); |
| 268 | + openwhiskInvoke.options.log = 'result' |
| 269 | + openwhiskInvoke.options.type = 'blocking' |
| 270 | + openwhiskInvoke.options.v = true |
| 271 | + |
| 272 | + const input = { |
| 273 | + activationId: 12345, |
| 274 | + name: 'blah', |
| 275 | + namespace: 'workspace', |
| 276 | + duration: 100, |
| 277 | + annotations: [ |
| 278 | + { key: "waitTime", value: 33 }, |
| 279 | + { key: "initTime", value: 63 } |
| 280 | + ], |
| 281 | + response: { success: true, result: { hello: "world"} } |
| 282 | + }; |
| 283 | + return openwhiskInvoke.log(input).then(() => { |
| 284 | + expect(log.calledTwice).to.be.equal(true); |
| 285 | + const msg = chalk.white(JSON.stringify(input.response.result, null, 4)); |
| 286 | + |
| 287 | + const field = (name, label) => `${chalk.blue(name)} (${chalk.yellow(label)})` |
| 288 | + const time = (name, value, color = 'blue') => `${chalk[color](name)}: ${chalk.green(value + 'ms')}` |
| 289 | + const duration = (duration, init = 0, wait) => `${time('duration', duration)} (${time('init', init, 'magenta')}, ${time('wait', wait, 'magenta')})` |
| 290 | + |
| 291 | + const output = `${chalk.green('=>')} ${field('action', '/workspace/blah')} ${field('activation', 12345)} ${duration(100, 63, 33)}` |
| 292 | + |
| 293 | + expect(log.args[0][0]).to.be.equal(output); |
| 294 | + expect(log.args[1][0]).to.be.equal(msg); |
| 295 | + }); |
| 296 | + }); |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + }); |
220 | 301 | });
|
0 commit comments