-
Notifications
You must be signed in to change notification settings - Fork 216
/
index.unit.test.js
198 lines (172 loc) · 6.25 KB
/
index.unit.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
'use strict'
/* global before beforeEach afterEach context */
const cli = require('heroku-cli-util')
const {expect} = require('chai')
const nock = require('nock')
const cmd = require('../../../..').commands.find(c => c.topic === 'pg' && c.command === 'backups')
describe('pg:backups', () => {
let pg
let transfers
beforeEach(() => {
pg = nock('https://postgres-api.heroku.com')
pg.get('/client/v11/apps/myapp/transfers').reply(200, transfers)
cli.mockConsole()
})
afterEach(() => {
nock.cleanAll()
pg.done()
})
context('with no backups/restores/copies', () => {
before(() => {
transfers = []
})
it('shows empty message', () => {
return cmd.run({app: 'myapp', args: []})
.then(() => expect(cli.stdout).to.equal(`=== Backups
No backups. Capture one with heroku pg:backups:capture
=== Restores
No restores found. Use heroku pg:backups:restore to restore a backup
=== Copies
No copies found. Use heroku pg:copy to copy a database to another
`))
})
})
context('with backups', () => {
before(() => {
transfers = [
{
num: 3,
from_name: 'DATABASE',
from_type: 'pg_dump',
to_type: 'gof3r',
processed_bytes: 1437,
succeeded: true,
warnings: 2,
created_at: '2016-10-08 00:42:54 +0000',
updated_at: '2016-10-08 00:43:04 +0000',
finished_at: '2016-10-08 00:43:00 +0000',
},
{
num: 10,
from_name: 'DATABASE',
from_type: 'pg_dump',
to_type: 'gof3r',
processed_bytes: 1437,
succeeded: true,
warnings: 0,
created_at: '2016-10-08 00:42:54 +0000',
finished_at: '2016-10-08 00:43:00 +0000',
schedule: {uuid: '5e5d5bc9-6aed-4ede-81b5-edf9341ee6d2'},
},
{
num: 4,
from_name: 'DATABASE',
from_type: 'pg_dump',
to_type: 'gof3r',
processed_bytes: 1437,
created_at: '2016-10-08 00:42:54 +0000',
finished_at: '2016-10-08 00:43:00 +0000',
},
{
num: 5,
from_name: 'DATABASE',
from_type: 'pg_dump',
to_type: 'gof3r',
processed_bytes: 1437,
created_at: '2016-10-08 00:42:54 +0000',
},
{
num: 6,
from_name: 'DATABASE',
from_type: 'pg_dump',
to_type: 'gof3r',
processed_bytes: 1437,
created_at: '2016-10-08 00:42:54 +0000',
started_at: '2016-10-08 00:42:54 +0000',
},
]
})
it('shows backups', () => {
return cmd.run({app: 'myapp', args: []})
.then(() => expect(cli.stdout).to.equal(`=== Backups
ID Created at Status Size Database
──── ───────────────────────── ─────────────────────────────────── ────── ────────
b006 2016-10-08 00:42:54 +0000 Running (processed 1.40KB) 1.40KB DATABASE
b005 2016-10-08 00:42:54 +0000 Pending 1.40KB DATABASE
b004 2016-10-08 00:42:54 +0000 Failed 2016-10-08 00:43:00 +0000 1.40KB DATABASE
a010 2016-10-08 00:42:54 +0000 Completed 2016-10-08 00:43:00 +0000 1.40KB DATABASE
b003 2016-10-08 00:42:54 +0000 Finished with 2 warnings 1.40KB DATABASE
=== Restores
No restores found. Use heroku pg:backups:restore to restore a backup
=== Copies
No copies found. Use heroku pg:copy to copy a database to another
`))
})
})
context('with restore', () => {
before(() => {
transfers = [
{
num: 3,
to_name: 'IVORY',
to_type: 'pg_restore',
processed_bytes: 1437,
succeeded: true,
warnings: 0,
created_at: '2016-10-08 00:42:54 +0000',
updated_at: '2016-10-08 00:43:04 +0000',
finished_at: '2016-10-08 00:43:00 +0000',
},
]
})
it('shows restore', () => {
return cmd.run({app: 'myapp', args: []})
.then(() => expect(cli.stdout).to.equal(`=== Backups
No backups. Capture one with heroku pg:backups:capture
=== Restores
ID Started at Status Size Database
──── ───────────────────────── ─────────────────────────────────── ────── ────────
r003 2016-10-08 00:42:54 +0000 Completed 2016-10-08 00:43:00 +0000 1.40KB IVORY
=== Copies
No copies found. Use heroku pg:copy to copy a database to another
`))
})
})
context('with copy', () => {
before(() => {
transfers = [
{
num: 3,
from_name: 'RED',
to_name: 'IVORY',
from_type: 'pg_dump',
to_type: 'pg_restore',
processed_bytes: 1437,
succeeded: true,
warnings: 0,
created_at: '2016-10-08 00:42:54 +0000',
updated_at: '2016-10-08 00:43:04 +0000',
finished_at: '2016-10-08 00:43:00 +0000',
},
]
})
it('shows copy', () => {
return cmd.run({app: 'myapp', args: []})
.then(() => expect(cli.stdout).to.equal(`=== Backups
No backups. Capture one with heroku pg:backups:capture
=== Restores
No restores found. Use heroku pg:backups:restore to restore a backup
=== Copies
ID Started at Status Size From To
──── ───────────────────────── ─────────────────────────────────── ────── ──── ─────
c003 2016-10-08 00:42:54 +0000 Completed 2016-10-08 00:43:00 +0000 1.40KB RED IVORY
`))
})
})
})
describe('pg:backups', () => {
const infoCmd = require('../../../..').commands.find(c => c.topic === 'pg' && c.command === 'backups:info')
it('errors out when subcommand not found', () => {
return expect(require('./helpers.js').dup('foobar', infoCmd)({})).to.be.rejectedWith('Unknown pg:backups command: foobar')
})
})