-
Notifications
You must be signed in to change notification settings - Fork 17
/
fail_test.js
113 lines (93 loc) · 3.84 KB
/
fail_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'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 nock = require('nock')
const cli = require('heroku-cli-util')
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/fail', {
'../lib/clusters': {
withCluster
}
})
describe('kafka:fail', () => {
let confirm
let kafka
let failUrl = (cluster) => {
return `/client/kafka/v0/clusters/${cluster}/induce-failure`
}
beforeEach(() => {
confirm = cli.confirmApp
kafka = nock('https://kafka-api.heroku.com:443')
cli.confirmApp = confirmApp
cli.mockConsole()
})
afterEach(() => {
cli.confirmApp = confirm
})
it('requires app confirmation', () => {
const app = 'myapp'
const cluster = 'kafka-1'
const message = `This command will affect the cluster: ${cluster}, which is on ${app}\n\nThis command will forcibly terminate nodes in your cluster at random.\nYou should only run this command in controlled testing scenarios.`
kafka.post(failUrl('00000000-0000-0000-0000-000000000000')).reply(200, { message: 'Triggered failure on node 1.2.3.4' })
return cmd.run({app: 'myapp', args: {}, flags: {confirm: 'myapp'}})
.then(() => {
expect(lastApp).to.equal('myapp')
expect(lastConfirm).to.equal('myapp')
expect(lastMsg).to.equal(message)
})
})
it('triggers failure', () => {
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: false,
zookeeper: false}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
return cmd.run({app: 'myapp',
args: {},
flags: {confirm: 'myapp',
catastrophic: false,
zookeeper: false}})
.then(() => expect(cli.stderr).to.equal('Eenie meenie miney moe... done\n'))
.then(() => expect(cli.stdout).to.equal('Triggered failure on node 1.2.3.4\n'))
})
it('passes the --catastrophic flag', () => {
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: true,
zookeeper: false}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
return cmd.run({app: 'myapp',
args: {},
flags: {confirm: 'myapp',
catastrophic: true,
zookeeper: false}})
.then(() => expect(cli.stderr).to.equal('Eenie meenie miney moe... done\n'))
.then(() => expect(cli.stdout).to.equal('Triggered failure on node 1.2.3.4\n'))
})
it('passes the --zookeeper flag', () => {
kafka.post(failUrl('00000000-0000-0000-0000-000000000000', {confirm: 'myapp',
catastrophic: false,
zookeeper: true}))
.reply(200, { message: 'Triggered failure on node 1.2.3.4' })
return cmd.run({app: 'myapp',
args: {},
flags: {confirm: 'myapp',
catastrophic: false,
zookeeper: true}})
.then(() => expect(cli.stderr).to.equal('Eenie meenie miney moe... done\n'))
.then(() => expect(cli.stdout).to.equal('Triggered failure on node 1.2.3.4\n'))
})
})