Skip to content

Commit

Permalink
Tweak topics list output slightly; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciek Sakrejda committed Oct 10, 2017
1 parent d6f024c commit ab15bf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
16 changes: 11 additions & 5 deletions commands/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ function * listTopics (context, heroku) {
})
cli.styledHeader('Kafka Topics on ' + (topics.attachment_name || 'HEROKU_KAFKA'))

if (topics.topics.length !== 0 && topics.limits && topics.limits.max_topics) {
cli.log(`${topics.topics.length} / ${topics.limits.max_topics} topics`)
}
if (topics.prefix) {
cli.log(`prefix: ${topics.prefix}`)
if (topics.topics.length !== 0) {
const extraInfo = []
if (topics.limits && topics.limits.max_topics) {
extraInfo.push(`${topics.topics.length} / ${topics.limits.max_topics} topics`)
}
if (topics.prefix) {
extraInfo.push(`prefix: ${cli.color.green(topics.prefix)}`)
}
if (extraInfo.length > 0) {
cli.log(extraInfo.join('; '))
}
}

let filtered = topics.topics.filter((t) => t.name !== '__consumer_offsets')
Expand Down
2 changes: 1 addition & 1 deletion commands/topics_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function topicInfo (topic) {
if (topic.prefix) {
lines.unshift({
name: 'Topic Prefix',
values: [ topic.prefix ]
values: [ cli.color.green(topic.prefix) ]
})
}

Expand Down
26 changes: 26 additions & 0 deletions test/commands/topics_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ Use heroku kafka:topics:create to create a topic.
.then(() => expect(cli.stdout).to.equal(`=== Kafka Topics on HEROKU_KAFKA_BLUE_URL
2 / 10 topics
Name Messages Traffic
─────── ──────── ───────────
topic-1 10/sec 0 bytes/sec
topic-2 12/sec 3 bytes/sec
`))
.then(() => expect(cli.stderr).to.be.empty)
})

it('includes prefix information if one exists', () => {
const prefix = 'russian-12345.'
kafka.get(topicsUrl('00000000-0000-0000-0000-000000000000')).reply(200, {
attachment_name: 'HEROKU_KAFKA_BLUE_URL',
prefix,
topics: [
{ name: 'topic-1', messages_in_per_second: 10.0, bytes_in_per_second: 0 },
{ name: 'topic-2', messages_in_per_second: 12.0, bytes_in_per_second: 3 }
],
limits: {
max_topics: 10
}
})

return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal(`=== Kafka Topics on HEROKU_KAFKA_BLUE_URL
2 / 10 topics; prefix: ${prefix}
Name Messages Traffic
─────── ──────── ───────────
topic-1 10/sec 0 bytes/sec
Expand Down

0 comments on commit ab15bf2

Please sign in to comment.