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..724b1d631d 100644 --- a/packages/spaces/commands/drains/get.js +++ b/packages/spaces/commands/drains/get.js @@ -13,10 +13,7 @@ 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, @@ -26,3 +23,8 @@ module.exports = { ], 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..544ecc91cb 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..0a7112fe13 100644 --- a/packages/spaces/index.js +++ b/packages/spaces/index.js @@ -1,3 +1,4 @@ + 'use strict' exports.topics = [ @@ -35,4 +36,4 @@ exports.commands = [ 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 d55a1580ce..23f369111f 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..a8b5fde646 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()) + }) }) })