-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathmaintenance.js
More file actions
119 lines (97 loc) · 5.45 KB
/
maintenance.js
File metadata and controls
119 lines (97 loc) · 5.45 KB
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
'use strict'
/* globals beforeEach cli */
let expect = require('chai').expect
let nock = require('nock')
let exit = require('heroku-cli-util').exit
let command = require('../../commands/maintenance')
const unwrap = require('../unwrap')
describe('heroku redis:maintenance', function () {
require('../lib/shared').shouldHandleArgs(command)
})
describe('heroku redis:maintenance', function () {
let newPluginMessage = ' ▸ You can also manage maintenances on your Redis instance with'
newPluginMessage += '\n ▸ data:maintenances.'
newPluginMessage += '\n ▸ Follow https://devcenter.heroku.com/articles/data-maintenance-cli-commands'
newPluginMessage += '\n ▸ to install the Data Maintenance CLI plugin.\n'
beforeEach(function () {
cli.mockConsole()
nock.cleanAll()
exit.mock()
})
it('# shows the maintenance message', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'premium-0'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
let redis = nock('https://redis-api.heroku.com:443')
.get('/redis/v0/databases/redis-haiku/maintenance').reply(200, {message: 'Message'})
return command.run({app: 'example', args: {}, flags: {}, auth: {username: 'foobar', password: 'password'}})
.then(() => app.done())
.then(() => redis.done())
.then(() => expect(cli.stdout).to.equal('Message\n'))
.then(() => expect(cli.stderr).to.equal(newPluginMessage))
})
it('# sets the maintenance window', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'premium-0'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
let redis = nock('https://redis-api.heroku.com:443')
.put('/redis/v0/databases/redis-haiku/maintenance_window', {
description: 'Mon 10:00',
}).reply(200, {window: 'Mon 10:00'})
return expect(command.run({app: 'example', args: {}, flags: {window: 'Mon 10:00'}, auth: {username: 'foobar', password: 'password'}})).to.be.rejectedWith(exit.ErrorExit)
.then(() => app.done())
.then(() => redis.done)
.then(() => expect(cli.stdout).to.equal('Maintenance window for redis-haiku (REDIS_FOO, REDIS_BAR) set to Mon 10:00.\n'))
.then(() => expect(cli.stderr).to.equal(newPluginMessage))
})
it('# runs the maintenance', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'premium-0'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
let appInfo = nock('https://api.heroku.com:443')
.get('/apps/example').reply(200, {maintenance: true})
let redis = nock('https://redis-api.heroku.com:443')
.post('/redis/v0/databases/redis-haiku/maintenance').reply(200, {message: 'Message'})
return expect(command.run({app: 'example', args: {}, flags: {run: true}, auth: {username: 'foobar', password: 'password'}})).to.be.rejectedWith(exit.ErrorExit)
.then(() => app.done())
.then(() => appInfo.done())
.then(() => redis.done())
.then(() => expect(cli.stdout).to.equal('Message\n'))
.then(() => expect(cli.stderr).to.equal(newPluginMessage))
})
it('# run errors out when not in maintenance', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'premium-0'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
let appInfo = nock('https://api.heroku.com:443')
.get('/apps/example').reply(200, {maintenance: false})
return expect(command.run({app: 'example', args: {}, flags: {run: true}, auth: {username: 'foobar', password: 'password'}})).to.be.rejectedWith(exit.ErrorExit)
.then(() => app.done())
.then(() => appInfo.done())
.then(() => expect(cli.stdout).to.equal(''))
.then(() => expect(unwrap(cli.stderr)).to.include('You must put your application in maintenance mode, or use the redis:maintenance --run --force command.\n'))
})
it('# errors out on mini instances', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'mini'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
return expect(command.run({app: 'example', args: {}, auth: {username: 'foobar', password: 'password'}})).to.be.rejected
.then(() => expect(unwrap(cli.stderr)).to.include('The redis:maintenance command is not available for Mini plans\n'))
.then(() => app.done())
})
it('# errors out on bad maintenance window', function () {
let app = nock('https://api.heroku.com:443')
.get('/apps/example/addons').reply(200, [
{name: 'redis-haiku', addon_service: {name: 'heroku-redis'}, plan: {name: 'premium-0'}, config_vars: ['REDIS_FOO', 'REDIS_BAR']},
])
return expect(command.run({app: 'example', args: {}, flags: {window: 'Mon 10:45'}, auth: {username: 'foobar', password: 'password'}})).to.be.rejected
.then(() => app.done())
.then(() => expect(cli.stdout).to.equal(''))
.then(() => expect(unwrap(cli.stderr)).to.include('Maintenance windows must be "Day HH:MM", where MM is 00 or 30.\n'))
})
})