-
Notifications
You must be signed in to change notification settings - Fork 17
/
info_test.js
176 lines (151 loc) · 5.19 KB
/
info_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
'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.beforeEach
const proxyquire = require('proxyquire')
const cli = require('heroku-cli-util')
const nock = require('nock')
let addon
let all = [
{name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000', plan: {name: 'heroku-kafka:beta-3'}},
{name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001', plan: {name: 'heroku-kafka:beta-3'}}
]
const fetcher = () => {
return {
all: () => all,
addon: () => addon
}
}
const cmd = proxyquire('../../commands/info', {
'../lib/fetcher': fetcher
}).info
describe('kafka:info', () => {
let api, kafka
let infoUrl = (cluster) => {
return `/data/kafka/v0/clusters/${cluster}`
}
beforeEach(() => {
api = nock('https://api.heroku.com:443')
kafka = nock('https://kafka-api.heroku.com:443')
cli.mockConsole()
})
afterEach(() => {
nock.cleanAll()
api.done()
kafka.done()
})
describe('with 0 dbs', () => {
it('shows empty state', () => {
all = []
return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal('myapp has no heroku-kafka clusters.\n'))
.then(() => expect(cli.stderr).to.be.empty)
})
})
describe('with 2 dbs', () => {
let plan = {name: 'heroku-kafka:beta-3'}
let attachments = [
{ addon: { name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' }, name: 'KAFKA' },
{ addon: { name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000' }, name: 'HEROKU_KAFKA_COBALT' },
{ addon: { name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001' }, name: 'HEROKU_KAFKA_PURPLE' }
]
let addonService = {name: 'heroku-kafka'}
let addons = [
{name: 'kafka-1', id: '00000000-0000-0000-0000-000000000000', addon_service: addonService, plan},
{name: 'kafka-2', id: '00000000-0000-0000-0000-000000000001', addon_service: addonService, plan}
]
let clusterA = {
addon: { name: 'kafka-1' },
state: { message: 'available' },
robot: { is_robot: false },
topics: ['__consumer_offsets', 'messages'],
messages_in_per_sec: 0,
bytes_in_per_sec: 0,
bytes_out_per_sec: 0,
version: ['0.10.0.0'],
created_at: '2016-11-14T14:26:20.245+00:00'
}
let clusterB = {
addon: { name: 'kafka-2' },
state: { message: 'available' },
robot: { is_robot: false },
topics: ['__consumer_offsets', 'messages'],
messages_in_per_sec: 0,
bytes_in_per_sec: 0,
bytes_out_per_sec: 0,
version: ['0.10.0.0'],
created_at: '2016-11-14T14:26:20.245+00:00'
}
it('shows kafka info', () => {
all = addons
api.get('/apps/myapp/addon-attachments').reply(200, attachments)
kafka
.get(infoUrl('00000000-0000-0000-0000-000000000000')).reply(200, clusterA)
.get(infoUrl('00000000-0000-0000-0000-000000000001')).reply(200, clusterB)
return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stderr).to.be.empty)
.then(() => expect(cli.stdout).to.equal(`=== KAFKA_URL, HEROKU_KAFKA_COBALT_URL
Plan: heroku-kafka:beta-3
Status: available
Version: 0.10.0.0
Created: 2016-11-14T14:26:20.245+00:00
Topics: 1 topic, see heroku kafka:topics
Messages: 0 messages/s
Traffic: 0 bytes/s in / 0 bytes/s out
Add-on: kafka-1
=== HEROKU_KAFKA_PURPLE_URL
Plan: heroku-kafka:beta-3
Status: available
Version: 0.10.0.0
Created: 2016-11-14T14:26:20.245+00:00
Topics: 1 topic, see heroku kafka:topics
Messages: 0 messages/s
Traffic: 0 bytes/s in / 0 bytes/s out
Add-on: kafka-2
`))
})
it('shows kafka info for single cluster when arg sent in', () => {
addon = addons[1]
api.get('/apps/myapp/addon-attachments').reply(200, attachments)
kafka
.get(infoUrl('00000000-0000-0000-0000-000000000001'))
.reply(200, clusterB)
return cmd.run({app: 'myapp', args: {CLUSTER: 'kafka-2'}})
.then(() => expect(cli.stderr).to.be.empty)
.then(() => expect(cli.stdout).to.equal(`=== HEROKU_KAFKA_PURPLE_URL
Plan: heroku-kafka:beta-3
Status: available
Version: 0.10.0.0
Created: 2016-11-14T14:26:20.245+00:00
Topics: 1 topic, see heroku kafka:topics
Messages: 0 messages/s
Traffic: 0 bytes/s in / 0 bytes/s out
Add-on: kafka-2
`))
})
it('shows warning for 404', () => {
all = addons
api.get('/apps/myapp/addon-attachments').reply(200, attachments)
kafka
.get(infoUrl('00000000-0000-0000-0000-000000000000')).reply(404)
.get(infoUrl('00000000-0000-0000-0000-000000000001')).reply(200, clusterB)
return cmd.run({app: 'myapp', args: {}})
.then(() => expect(cli.stdout).to.equal(`=== HEROKU_KAFKA_PURPLE_URL
Plan: heroku-kafka:beta-3
Status: available
Version: 0.10.0.0
Created: 2016-11-14T14:26:20.245+00:00
Topics: 1 topic, see heroku kafka:topics
Messages: 0 messages/s
Traffic: 0 bytes/s in / 0 bytes/s out
Add-on: kafka-2
`))
.then(() => expect(cli.stderr).to.equal(` ▸ kafka-1 is not yet provisioned.
▸ Run heroku kafka:wait to wait until the cluster is provisioned.
`))
})
})
})