From 57d306ad7f9637466b3da9667f9109b6860c9bf4 Mon Sep 17 00:00:00 2001 From: Matt Blewitt <118200221+mble-sfdc@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:16:05 +0100 Subject: [PATCH 1/2] feat(spaces): migrate drains:{set,get} to spaces topic This commit partially migrates the `drains:set` and `drains:get` commands for `spaces` under the `spaces` topic, so they can be accessed from `spaces:drains:set` and `spaces:drains:get`. The rationale here is that these are `spaces`-specific commands, and there is significant semantic overlap between `drains:add` and `drains:set`. This makes it clearer that these commands are `spaces`-specific. In order to not break comaptibility with existing workflows, the old `drains:{set,get}` commands will continue to work, but remain hidden. --- .../cli/test/acceptance/commands-output.ts | 2 + packages/spaces/commands/drains/get.js | 14 +++-- packages/spaces/commands/drains/set.js | 10 +-- packages/spaces/index.js | 6 +- .../unit/commands/drains/get.unit.test.js | 62 ++++++++++--------- .../unit/commands/drains/set.unit.test.js | 43 ++++++------- 6 files changed, 74 insertions(+), 63 deletions(-) diff --git a/packages/cli/test/acceptance/commands-output.ts b/packages/cli/test/acceptance/commands-output.ts index a49e81d7a2..43cd1c28b6 100644 --- a/packages/cli/test/acceptance/commands-output.ts +++ b/packages/cli/test/acceptance/commands-output.ts @@ -275,6 +275,8 @@ export default `\u001B[1m Command Summary spaces list available spaces spaces:create create a new space spaces:destroy destroy a space + spaces:drains:get display the log drain for a space + spaces:drains:set replaces the log drain for a space spaces:info show info about a space spaces:peering:info display the information necessary to initiate a peering connection spaces:peerings list peering connections for a space diff --git a/packages/spaces/commands/drains/get.js b/packages/spaces/commands/drains/get.js index e69a56479f..8153a474fc 100644 --- a/packages/spaces/commands/drains/get.js +++ b/packages/spaces/commands/drains/get.js @@ -13,16 +13,18 @@ async function run(context, heroku) { } } -module.exports = { - topic: 'drains', - command: 'get', - hidden: true, +const cmd = { description: 'display the log drain for a space', needsApp: false, needsAuth: true, flags: [ - {name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true}, - {name: 'json', description: 'output in json format'}, + { name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true }, + { name: 'json', description: 'output in json format' }, ], run: cli.command(run), } + +module.exports = [ + Object.assign({topic: 'spaces', command: 'drains:get', hidden: false}, cmd), + Object.assign({topic: 'drains', command: 'get', hidden: true}, cmd) +] diff --git a/packages/spaces/commands/drains/set.js b/packages/spaces/commands/drains/set.js index b28d1da095..fe911ceba1 100644 --- a/packages/spaces/commands/drains/set.js +++ b/packages/spaces/commands/drains/set.js @@ -10,10 +10,7 @@ async function run(context, heroku) { cli.warn('It may take a few moments for the changes to take effect.') } -module.exports = { - topic: 'drains', - command: 'set', - hidden: true, +const cmd = { description: 'replaces the log drain for a space', needsApp: false, needsAuth: true, @@ -25,3 +22,8 @@ module.exports = { ], run: cli.command(run), } + +module.exports = [ + Object.assign({topic: 'spaces', command: 'drains:set', hidden: false}, cmd), + Object.assign({topic: 'drains', command: 'set', hidden: true}, cmd) +] diff --git a/packages/spaces/index.js b/packages/spaces/index.js index 079b417084..139e879edb 100644 --- a/packages/spaces/index.js +++ b/packages/spaces/index.js @@ -1,11 +1,13 @@ 'use strict' +const _ = require('lodash') + exports.topics = [ {name: 'spaces', description: 'manage heroku private spaces'}, {name: 'trusted-ips', hidden: true}, ] -exports.commands = [ +exports.commands = _.flatten([ require('./commands'), require('./commands/create'), require('./commands/destroy'), @@ -35,4 +37,4 @@ exports.commands = [ require('./commands/outbound-rules/add'), require('./commands/outbound-rules/remove'), require('./commands/hosts'), -] +]) diff --git a/packages/spaces/test/unit/commands/drains/get.unit.test.js b/packages/spaces/test/unit/commands/drains/get.unit.test.js index d55a1580ce..c7445e2329 100644 --- a/packages/spaces/test/unit/commands/drains/get.unit.test.js +++ b/packages/spaces/test/unit/commands/drains/get.unit.test.js @@ -2,46 +2,48 @@ /* globals beforeEach */ let nock = require('nock') -let cmd = require('../../../../commands/drains/get') +let cmds = require('../../../../commands/drains/get') let expect = require('chai').expect let cli = require('heroku-cli-util') -describe('drains:get', function () { - beforeEach(() => cli.mockConsole()) +cmds.forEach(cmd => { + describe(`${cmd.topic}:${cmd.command}`, function () { + beforeEach(() => cli.mockConsole()) - it('shows the log drain', function () { - let api = nock('https://api.heroku.com:443') - .get('/spaces/my-space/log-drain') - .reply(200, { + it('shows the log drain', function () { + let api = nock('https://api.heroku.com:443') + .get('/spaces/my-space/log-drain') + .reply(200, { + addon: null, + created_at: '2016-03-23T18:31:50Z', + id: '047f80cc-0470-4564-b0cb-e9ad7605314a', + token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19', + updated_at: '2016-03-23T18:31:50Z', + url: 'https://example.com', + }) + return cmd.run({flags: {space: 'my-space'}}) + .then(() => expect(cli.stdout).to.equal( + `https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n`, + )).then(() => api.done()) + }) + + it('shows the log drain --json', function () { + let drain = { addon: null, created_at: '2016-03-23T18:31:50Z', id: '047f80cc-0470-4564-b0cb-e9ad7605314a', token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19', updated_at: '2016-03-23T18:31:50Z', url: 'https://example.com', - }) - return cmd.run({flags: {space: 'my-space'}}) - .then(() => expect(cli.stdout).to.equal( - `https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19) -`, - )).then(() => api.done()) - }) + } - it('shows the log drain --json', function () { - let drain = { - addon: null, - created_at: '2016-03-23T18:31:50Z', - id: '047f80cc-0470-4564-b0cb-e9ad7605314a', - token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19', - updated_at: '2016-03-23T18:31:50Z', - url: 'https://example.com', - } - - let api = nock('https://api.heroku.com:443') - .get('/spaces/my-space/log-drain') - .reply(200, drain) - return cmd.run({flags: {space: 'my-space', json: true}}) - .then(() => expect(JSON.parse(cli.stdout)).to.eql(drain)) - .then(() => api.done()) + let api = nock('https://api.heroku.com:443') + .get('/spaces/my-space/log-drain') + .reply(200, drain) + return cmd.run({flags: {space: 'my-space', json: true}}) + .then(() => expect(JSON.parse(cli.stdout)).to.eql(drain)) + .then(() => api.done()) + }) }) }) + diff --git a/packages/spaces/test/unit/commands/drains/set.unit.test.js b/packages/spaces/test/unit/commands/drains/set.unit.test.js index 8c33c8a1ca..510baf6610 100644 --- a/packages/spaces/test/unit/commands/drains/set.unit.test.js +++ b/packages/spaces/test/unit/commands/drains/set.unit.test.js @@ -2,30 +2,31 @@ /* globals beforeEach */ let nock = require('nock') -let cmd = require('../../../../commands/drains/set') +let cmds = require('../../../../commands/drains/set') let expect = require('chai').expect let cli = require('heroku-cli-util') -describe('drains:set', function () { - beforeEach(() => cli.mockConsole()) +cmds.forEach(cmd => { + describe(`${cmd.topic}:${cmd.command}`, function () { + beforeEach(() => cli.mockConsole()) - it('shows the log drain', function () { - let api = nock('https://api.heroku.com:443') - .put('/spaces/my-space/log-drain', { - url: 'https://example.com', - }) - .reply(200, { - addon: null, - created_at: '2016-03-23T18:31:50Z', - id: '047f80cc-0470-4564-b0cb-e9ad7605314a', - token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19', - updated_at: '2016-03-23T18:31:50Z', - url: 'https://example.com', - }) - return cmd.run({args: {url: 'https://example.com'}, flags: {space: 'my-space'}}) - .then(() => expect(cli.stdout).to.equal( - `Successfully set drain https://example.com for my-space. -`, - )).then(() => api.done()) + it('shows the log drain', function () { + let api = nock('https://api.heroku.com:443') + .put('/spaces/my-space/log-drain', { + url: 'https://example.com', + }) + .reply(200, { + addon: null, + created_at: '2016-03-23T18:31:50Z', + id: '047f80cc-0470-4564-b0cb-e9ad7605314a', + token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19', + updated_at: '2016-03-23T18:31:50Z', + url: 'https://example.com', + }) + return cmd.run({args: {url: 'https://example.com'}, flags: {space: 'my-space'}}) + .then(() => expect(cli.stdout).to.equal( + `Successfully set drain https://example.com for my-space.\n`, + )).then(() => api.done()) + }) }) }) From 78d1197b21b32405129af7d94f02349e168365ca Mon Sep 17 00:00:00 2001 From: Matt Blewitt <118200221+mble-sfdc@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:24:34 +0000 Subject: [PATCH 2/2] fix formatting drift --- packages/spaces/commands/drains/get.js | 6 +++--- packages/spaces/commands/drains/set.js | 2 +- packages/spaces/index.js | 7 +++---- packages/spaces/test/unit/commands/drains/get.unit.test.js | 2 +- packages/spaces/test/unit/commands/drains/set.unit.test.js | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/spaces/commands/drains/get.js b/packages/spaces/commands/drains/get.js index 8153a474fc..724b1d631d 100644 --- a/packages/spaces/commands/drains/get.js +++ b/packages/spaces/commands/drains/get.js @@ -18,13 +18,13 @@ const cmd = { needsApp: false, needsAuth: true, flags: [ - { name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true }, - { name: 'json', description: 'output in json format' }, + {name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true}, + {name: 'json', description: 'output in json format'}, ], run: cli.command(run), } module.exports = [ Object.assign({topic: 'spaces', command: 'drains:get', hidden: false}, cmd), - Object.assign({topic: 'drains', command: 'get', hidden: true}, cmd) + Object.assign({topic: 'drains', command: 'get', hidden: true}, cmd), ] diff --git a/packages/spaces/commands/drains/set.js b/packages/spaces/commands/drains/set.js index fe911ceba1..544ecc91cb 100644 --- a/packages/spaces/commands/drains/set.js +++ b/packages/spaces/commands/drains/set.js @@ -25,5 +25,5 @@ const cmd = { module.exports = [ Object.assign({topic: 'spaces', command: 'drains:set', hidden: false}, cmd), - Object.assign({topic: 'drains', command: 'set', hidden: true}, cmd) + Object.assign({topic: 'drains', command: 'set', hidden: true}, cmd), ] diff --git a/packages/spaces/index.js b/packages/spaces/index.js index 139e879edb..0a7112fe13 100644 --- a/packages/spaces/index.js +++ b/packages/spaces/index.js @@ -1,13 +1,12 @@ -'use strict' -const _ = require('lodash') +'use strict' exports.topics = [ {name: 'spaces', description: 'manage heroku private spaces'}, {name: 'trusted-ips', hidden: true}, ] -exports.commands = _.flatten([ +exports.commands = [ require('./commands'), require('./commands/create'), require('./commands/destroy'), @@ -37,4 +36,4 @@ exports.commands = _.flatten([ require('./commands/outbound-rules/add'), require('./commands/outbound-rules/remove'), require('./commands/hosts'), -]) +].flat() diff --git a/packages/spaces/test/unit/commands/drains/get.unit.test.js b/packages/spaces/test/unit/commands/drains/get.unit.test.js index c7445e2329..23f369111f 100644 --- a/packages/spaces/test/unit/commands/drains/get.unit.test.js +++ b/packages/spaces/test/unit/commands/drains/get.unit.test.js @@ -23,7 +23,7 @@ cmds.forEach(cmd => { }) return cmd.run({flags: {space: 'my-space'}}) .then(() => expect(cli.stdout).to.equal( - `https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n`, + 'https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n', )).then(() => api.done()) }) diff --git a/packages/spaces/test/unit/commands/drains/set.unit.test.js b/packages/spaces/test/unit/commands/drains/set.unit.test.js index 510baf6610..a8b5fde646 100644 --- a/packages/spaces/test/unit/commands/drains/set.unit.test.js +++ b/packages/spaces/test/unit/commands/drains/set.unit.test.js @@ -25,7 +25,7 @@ cmds.forEach(cmd => { }) return cmd.run({args: {url: 'https://example.com'}, flags: {space: 'my-space'}}) .then(() => expect(cli.stdout).to.equal( - `Successfully set drain https://example.com for my-space.\n`, + 'Successfully set drain https://example.com for my-space.\n', )).then(() => api.done()) }) })