-
Notifications
You must be signed in to change notification settings - Fork 17
/
topics_destroy_test.js
88 lines (71 loc) · 2.33 KB
/
topics_destroy_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'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' })
}
let lastApp
let lastConfirm
let lastMsg
const confirmApp = function * (app, confirm, msg) {
lastApp = app
lastConfirm = confirm
lastMsg = msg
}
const cmd = proxyquire('../../commands/topics_destroy', {
'../lib/clusters': {
withCluster
}
}).cmd
describe('kafka:topics:destroy', () => {
let confirm
let kafka
let deleteUrl = (cluster, topic) => {
return `/data/kafka/v0/clusters/${cluster}/topics/${topic}`
}
beforeEach(() => {
confirm = cli.confirmApp
kafka = nock('https://kafka-api.heroku.com:443')
cli.exit.mock()
cli.confirmApp = confirmApp
cli.mockConsole()
})
afterEach(() => {
cli.confirmApp = confirm
nock.cleanAll()
kafka.done()
})
it('requires app confirmation', () => {
const message = 'This command will affect the cluster: kafka-1, which is on myapp'
kafka.delete(deleteUrl('00000000-0000-0000-0000-000000000000', 'topic-1')).reply(200)
lastApp = null
lastConfirm = null
lastMsg = null
return cmd.run({app: 'myapp',
args: { TOPIC: 'topic-1' },
flags: { confirm: 'myapp' }})
.then(() => {
expect(lastApp).to.equal('myapp')
expect(lastConfirm).to.equal('myapp')
expect(lastMsg).to.equal(message)
})
})
it('deletes the topic', () => {
kafka.delete(deleteUrl('00000000-0000-0000-0000-000000000000', 'topic-1'), { topic_name: 'topic-1' })
.reply(200)
return cmd.run({app: 'myapp',
args: { TOPIC: 'topic-1' },
flags: { 'replication-factor': '3', confirm: 'myapp' }})
.then(() => {
expect(cli.stdout).to.equal('Your topic has been marked for deletion, and will be removed from the cluster shortly\n')
expect(cli.stderr).to.equal('Deleting topic topic-1... done\n')
})
})
})