Skip to content

Commit

Permalink
add support for displaying prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning committed Jan 27, 2017
1 parent 73fa2ae commit 01166d5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function formatInfo (info) {
values: [`${topicCount} ${humanize.pluralize(topicCount, 'topic')}, see heroku kafka:topics`]
})

if (cluster.topic_prefix) {
lines.push({ name: 'Prefix', values: [cluster.topic_prefix] })
}

lines.push({
name: 'Messages',
values: [`${humanize.intComma(cluster.messages_in_per_sec)} ${humanize.pluralize(cluster.messages_in_per_sec, 'message')}/s`]
Expand Down
40 changes: 40 additions & 0 deletions commands/prefix.js
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))
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.commands = [
require('./commands/consumer_groups_create.js'),
require('./commands/consumer_groups_destroy.js'),
require('./commands/fail.js'),
require('./commands/prefix.js'),
require('./commands/upgrade.js'),
require('./commands/info.js').info,
require('./commands/info.js').root,
Expand Down
53 changes: 53 additions & 0 deletions test/commands/prefix_test.js
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`))
})
})

0 comments on commit 01166d5

Please sign in to comment.