From 41713e2199fd82390e748b896e7b4060e614f69a Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Wed, 13 May 2020 14:46:36 -0700 Subject: [PATCH] Handle case where we do not receive any logs back (#163) * Handle case where we do not receive any logs back * matching test --- src/commands/runtime/activation/logs.js | 4 ++++ test/commands/runtime/activation/logs.test.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/commands/runtime/activation/logs.js b/src/commands/runtime/activation/logs.js index 3fa5795b..9927a43f 100644 --- a/src/commands/runtime/activation/logs.js +++ b/src/commands/runtime/activation/logs.js @@ -25,6 +25,10 @@ class ActivationLogs extends RuntimeBaseCommand { if (flags.last) { const limit = Math.max(1, Math.min(flags.count, 5)) activations = await ow.activations.list({ limit: limit, skip: 0 }) + if (!activations || activations.length < 1) { + this.log('No activations to log.') + return + } } if (!activations[0].activationId) { // just a thought, but we could just return --last activation log when no id is present diff --git a/test/commands/runtime/activation/logs.test.js b/test/commands/runtime/activation/logs.test.js index 759b893c..e2e03d46 100644 --- a/test/commands/runtime/activation/logs.test.js +++ b/test/commands/runtime/activation/logs.test.js @@ -115,6 +115,16 @@ describe('instance methods', () => { }) }) + test('retrieve last logs - no-results', () => { + const cmd = ow.mockResolved('activations.list', []) + command.argv = ['-l'] + return command.run() + .then(() => { + expect(cmd).toHaveBeenCalledWith(expect.objectContaining({ limit: 1 })) + expect(stdout.output).toMatch('') + }) + }) + test('retrieve last log --last', () => { const listCmd = ow.mockResolved('activations.list', [{ activationId: '12345' }]) const logCmd = ow.mockResolved(owAction, { logs: ['line1', 'line2', 'line3'] })