Skip to content

Commit ed67ab2

Browse files
authored
migrate(W-14169233): spaces: Upgrade drains:set (#2851)
1 parent 89201a4 commit ed67ab2

File tree

6 files changed

+54
-71
lines changed

6 files changed

+54
-71
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import color from '@heroku-cli/color'
2+
import {Command, flags} from '@heroku-cli/command'
3+
import {Args, ux} from '@oclif/core'
4+
import * as Heroku from '@heroku-cli/schema'
5+
6+
export default class Set extends Command {
7+
static topic = 'drains'
8+
static hidden = true
9+
static description = 'replaces the log drain for a space'
10+
static flags = {
11+
space: flags.string({char: 's', description: 'space for which to set log drain', required: true}),
12+
}
13+
14+
static args = {
15+
url: Args.string({required: true}),
16+
}
17+
18+
public async run(): Promise<void> {
19+
const {flags, args} = await this.parse(Set)
20+
const {url} = args
21+
const {space} = flags
22+
const {body: drain} = await this.heroku.put<Heroku.LogDrain>(`/spaces/${space}/log-drain`, {
23+
body: {url},
24+
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
25+
})
26+
ux.log(`Successfully set drain ${color.cyan(drain.url)} for ${color.cyan.bold(space)}.`)
27+
ux.warn('It may take a few moments for the changes to take effect.')
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {expect} from '@oclif/test'
2+
import * as nock from 'nock'
3+
import {stdout} from 'stdout-stderr'
4+
import runCommand from '../../../helpers/runCommand'
5+
import Cmd from '../../../../src/commands/drains/set'
6+
7+
describe('drains:set', function () {
8+
it('shows the log drain', async function () {
9+
const api = nock('https://api.heroku.com:443')
10+
.put('/spaces/my-space/log-drain', {
11+
url: 'https://example.com',
12+
})
13+
.reply(200, {
14+
addon: null,
15+
created_at: '2016-03-23T18:31:50Z',
16+
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
17+
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
18+
updated_at: '2016-03-23T18:31:50Z',
19+
url: 'https://example.com',
20+
})
21+
await runCommand(Cmd, ['https://example.com', '--space', 'my-space'])
22+
expect(stdout.output).to.equal('Successfully set drain https://example.com for my-space.\n')
23+
api.done()
24+
})
25+
})

packages/spaces/commands/drains/set.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/spaces/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exports.commands = [
1919
require('./commands/vpn/update'),
2020
require('./commands/transfer'),
2121
require('./commands/drains/get'),
22-
require('./commands/drains/set'),
2322
require('./commands/trusted-ips'),
2423
require('./commands/trusted-ips/add'),
2524
require('./commands/trusted-ips/remove'),

packages/spaces/lib/log-drains.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ module.exports = function (heroku) {
88
})
99
}
1010

11-
function putLogDrain(space, url) {
12-
return heroku.request({
13-
method: 'PUT',
14-
path: `/spaces/${space}/log-drain`,
15-
body: {
16-
url: url,
17-
},
18-
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
19-
})
20-
}
21-
2211
return {
2312
getLogDrain,
24-
putLogDrain,
2513
}
2614
}

packages/spaces/test/unit/commands/drains/set.unit.test.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)