This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
push.js
151 lines (128 loc) · 6.41 KB
/
push.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
'use strict'
const cli = require('heroku-cli-util')
const cmd = require('../..').commands.find(c => c.topic === 'container' && c.command === 'push')
const expect = require('unexpected')
const sinon = require('sinon')
const nock = require('nock')
const Sanbashi = require('../../lib/sanbashi')
var sandbox
describe('container push', () => {
beforeEach(() => {
cli.mockConsole()
sandbox = sinon.createSandbox()
})
afterEach(() => sandbox.restore())
it('gets a build error', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns(['/path/to/Dockerfile'])
let build = sandbox.stub(Sanbashi, 'buildImage').throws()
return cmd.run({app: 'testapp', args: ['web'], flags: {}})
.then(() => expect(cli.stderr, 'to contain', 'docker build exited with Error: Error'))
.then(() => expect(cli.stdout, 'to contain', 'Building web (/path/to/Dockerfile)'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => sandbox.assert.calledOnce(build))
.then(() => api.done())
})
it('gets a push error', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns(['/path/to/Dockerfile'])
let build = sandbox.stub(Sanbashi, 'buildImage')
let push = sandbox.stub(Sanbashi, 'pushImage').throws()
return cmd.run({app: 'testapp', args: ['web'], flags: {}})
.then(() => expect(cli.stderr, 'to contain', 'docker push exited with Error: Error'))
.then(() => expect(cli.stdout, 'to contain', 'Building web (/path/to/Dockerfile)'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => sandbox.assert.calledOnce(build))
.then(() => sandbox.assert.calledOnce(push))
.then(() => api.done())
})
it('pushes to the docker registry', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns(['/path/to/Dockerfile'])
let build = sandbox.stub(Sanbashi, 'buildImage')
.withArgs('/path/to/Dockerfile', 'registry.heroku.com/testapp/web', [])
let push = sandbox.stub(Sanbashi, 'pushImage')
.withArgs('registry.heroku.com/testapp/web')
return cmd.run({app: 'testapp', args: ['web'], flags: {}})
// .then(() => expect(cli.stderr, 'to be empty'))
.then(() => expect(cli.stdout, 'to contain', 'Building web (/path/to/Dockerfile)'))
.then(() => expect(cli.stdout, 'to contain', 'Pushing web (/path/to/Dockerfile)'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => sandbox.assert.calledOnce(build))
.then(() => sandbox.assert.calledOnce(push))
.then(() => api.done())
})
it('pushes the standard dockerfile to non-web', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns(['/path/to/Dockerfile'])
let build = sandbox.stub(Sanbashi, 'buildImage')
.withArgs('/path/to/Dockerfile', 'registry.heroku.com/testapp/worker', [])
let push = sandbox.stub(Sanbashi, 'pushImage')
.withArgs('registry.heroku.com/testapp/worker')
return cmd.run({app: 'testapp', args: ['worker'], flags: {}})
// .then(() => expect(cli.stderr, 'to be empty'))
.then(() => expect(cli.stdout, 'to contain', 'Building worker (/path/to/Dockerfile)'))
.then(() => expect(cli.stdout, 'to contain', 'Pushing worker (/path/to/Dockerfile)'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => sandbox.assert.calledOnce(build))
.then(() => sandbox.assert.calledOnce(push))
.then(() => api.done())
})
it('pushes several dockerfiles recursively', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns(['/path/to/Dockerfile.web', '/path/to/Dockerfile.worker'])
let build = sandbox.stub(Sanbashi, 'buildImage')
build.withArgs('/path/to/Dockerfile.web', 'registry.heroku.com/testapp/web', [])
build.withArgs('/path/to/Dockerfile.worker', 'registry.heroku.com/testapp/worker', [])
let push = sandbox.stub(Sanbashi, 'pushImage')
push.withArgs('registry.heroku.com/testapp/web')
push.withArgs('registry.heroku.com/testapp/worker')
return cmd.run({app: 'testapp', args: ['web', 'worker'], flags: {recursive: true}})
// .then(() => expect(cli.stderr, 'to be empty'))
.then(() => expect(cli.stdout, 'to contain', 'Building web (/path/to/Dockerfile.web)'))
.then(() => expect(cli.stdout, 'to contain', 'Building worker (/path/to/Dockerfile.worker)'))
.then(() => expect(cli.stdout, 'to contain', 'Pushing web (/path/to/Dockerfile.web)'))
.then(() => expect(cli.stdout, 'to contain', 'Pushing worker (/path/to/Dockerfile.worker)'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => sandbox.assert.calledTwice(build))
.then(() => sandbox.assert.calledTwice(push))
.then(() => api.done())
})
it('does not find an image to push', () => {
let api = nock('https://api.heroku.com:443')
.get('/apps/testapp')
.reply(200, {name: 'testapp'})
let dockerfiles = sandbox.stub(Sanbashi, 'getDockerfiles')
.returns([])
return cmd.run({app: 'testapp', args: ['web'], flags: {}})
.then(() => expect(cli.stderr, 'to contain', 'No images to push'))
.then(() => expect(cli.stdout, 'to be empty'))
.then(() => sandbox.assert.calledOnce(dockerfiles))
.then(() => api.done())
})
it('requires a process type if we are not recursive', () => {
return cmd.run({app: 'testapp', args: [], flags: {}})
.then(() => expect(cli.stderr, 'to contain', 'Requires either --recursive or one or more process types'))
.then(() => expect(cli.stdout, 'to be empty'))
})
it('rejects multiple process types if we are not recursive', () => {
return cmd.run({app: 'testapp', args: ['web', 'worker'], flags: {}})
.then(() => expect(cli.stderr, 'to contain', 'Requires exactly one target process type, or --recursive option'))
.then(() => expect(cli.stdout, 'to be empty'))
})
})