Skip to content

Commit

Permalink
feat(spaces): migrate drains:{set,get} to spaces topic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mble-sfdc committed Aug 11, 2023
1 parent 0d7e5ca commit 57d306a
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 63 deletions.
2 changes: 2 additions & 0 deletions packages/cli/test/acceptance/commands-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions packages/spaces/commands/drains/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
10 changes: 6 additions & 4 deletions packages/spaces/commands/drains/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
]
6 changes: 4 additions & 2 deletions packages/spaces/index.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down Expand Up @@ -35,4 +37,4 @@ exports.commands = [
require('./commands/outbound-rules/add'),
require('./commands/outbound-rules/remove'),
require('./commands/hosts'),
]
])
62 changes: 32 additions & 30 deletions packages/spaces/test/unit/commands/drains/get.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
})

43 changes: 22 additions & 21 deletions packages/spaces/test/unit/commands/drains/set.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
})

0 comments on commit 57d306a

Please sign in to comment.