-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 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
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,40 @@ | ||
'use strict' | ||
|
||
let cli = require('heroku-cli-util') | ||
let co = require('co') | ||
let withCluster = require('../lib/clusters').withCluster | ||
let request = require('../lib/clusters').request | ||
|
||
const VERSION = 'v0' | ||
|
||
function * kafkaPrefix (context, heroku) { | ||
yield withCluster(heroku, context.app, context.args.CLUSTER, function * (addon) { | ||
let info = yield request(heroku, { | ||
path: `/data/kafka/${VERSION}/clusters/${addon.id}` | ||
}) | ||
|
||
if (info.topic_prefix) { | ||
cli.log(info.topic_prefix) | ||
} else { | ||
cli.log('No prefix found.') | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
topic: 'kafka', | ||
command: 'prefix', | ||
description: 'display user prefix', | ||
help: ` | ||
Displays user prefix. | ||
Examples: | ||
$ heroku kafka:prefix | ||
$ heroku kafka:prefix HEROKU_KAFKA_BROWN_URL | ||
`, | ||
needsApp: true, | ||
needsAuth: true, | ||
args: [{name: 'CLUSTER', optional: true}], | ||
run: cli.command({preauth: true}, co.wrap(kafkaPrefix)) | ||
} |
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 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,53 @@ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const mocha = require('mocha') | ||
const describe = mocha.describe | ||
const it = mocha.it | ||
const beforeEach = mocha.beforeEach | ||
const afterEach = mocha.afterEach | ||
const proxyquire = require('proxyquire') | ||
|
||
const cli = require('heroku-cli-util') | ||
const nock = require('nock') | ||
|
||
const withCluster = function * (heroku, app, cluster, callback) { | ||
yield callback({ name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' }) | ||
} | ||
|
||
const VERSION = 'v0' | ||
|
||
const cmd = proxyquire('../../commands/prefix', { | ||
'../lib/clusters': { | ||
withCluster | ||
} | ||
}) | ||
|
||
describe('kafka:prefix', () => { | ||
let kafka | ||
|
||
let consumerGroupsUrl = (cluster) => { | ||
return `/data/kafka/${VERSION}/clusters/${cluster}` | ||
} | ||
|
||
beforeEach(() => { | ||
kafka = nock('https://kafka-api.heroku.com:443') | ||
cli.mockConsole() | ||
cli.exit.mock() | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
kafka.done() | ||
}) | ||
|
||
it('displays a prefix', () => { | ||
kafka.get(consumerGroupsUrl('00000000-0000-0000-0000-000000000000')).reply(200, { | ||
attachment_name: 'HEROKU_KAFKA', | ||
topic_prefix: 'nile-123.' | ||
}) | ||
|
||
return cmd.run({app: 'myapp', args: {}}) | ||
.then(() => expect(cli.stdout).to.equal(`nile-123.\n`)) | ||
}) | ||
}) |