-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move command 'spaces:drains:get' to CLI
- Loading branch information
Showing
8 changed files
with
81 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
|
||
export default class Get extends Command { | ||
static aliases = ['drains:get'] | ||
static topic = 'drains' | ||
static hidden = true | ||
static description = 'display the log drain for a space' | ||
static flags = { | ||
space: flags.string({char: 's', description: 'space for which to get log drain', required: true}), | ||
json: flags.boolean({description: 'output in json format'}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags} = await this.parse(Get) | ||
const {space, json} = flags | ||
const {body: drain} = await this.heroku.get<Required<Heroku.LogDrain>>( | ||
`/spaces/${space}/log-drain`, | ||
{headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'}}, | ||
) | ||
|
||
if (json) { | ||
ux.log(JSON.stringify(drain, null, 2)) | ||
} else { | ||
ux.log(`${color.cyan(drain.url)} (${color.green(drain.token)})`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {stdout} from 'stdout-stderr' | ||
import runCommand from '../../../../helpers/runCommand' | ||
import Cmd from '../../../../../src/commands/spaces/drains/get' | ||
import {expect} from 'chai' | ||
import * as nock from 'nock' | ||
|
||
describe('spaces:drains:get', function () { | ||
const 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.Scope | ||
|
||
beforeEach(function () { | ||
api = nock('https://api.heroku.com') | ||
.get('/spaces/my-space/log-drain') | ||
.reply(200, drain) | ||
}) | ||
|
||
afterEach(function () { | ||
api.done() | ||
nock.cleanAll() | ||
}) | ||
|
||
it('shows the log drain', async function () { | ||
await runCommand(Cmd, [ | ||
'--space', | ||
'my-space', | ||
]) | ||
|
||
expect(stdout.output).to.eq('https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n') | ||
}) | ||
|
||
it('shows the log drain --json', async function () { | ||
await runCommand(Cmd, [ | ||
'--space', | ||
'my-space', | ||
'--json', | ||
]) | ||
|
||
expect(JSON.parse(stdout.output)).to.eql(drain) | ||
}) | ||
}) |
6 changes: 3 additions & 3 deletions
6
...est/unit/commands/drains/set.unit.test.ts → ...t/commands/spaces/drains/set.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
packages/spaces/test/unit/commands/drains/get.unit.test.js
This file was deleted.
Oops, something went wrong.