Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spaces): migrate drains:{set,get} to spaces topic #2433

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 6 additions & 4 deletions packages/spaces/commands/drains/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
]
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),
]
3 changes: 2 additions & 1 deletion packages/spaces/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

'use strict'

exports.topics = [
Expand Down Expand Up @@ -35,4 +36,4 @@ exports.commands = [
require('./commands/outbound-rules/add'),
require('./commands/outbound-rules/remove'),
require('./commands/hosts'),
]
].flat()
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())
})
})
})
Loading