forked from shipitjs/shipit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipit.js
139 lines (116 loc) · 3.71 KB
/
shipit.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
var sinon = require('sinon');
var expect = require('chai').use(require('sinon-chai')).expect;
var stream = require('mock-utf8-stream');
var ConnectionPool = require('ssh-pool').ConnectionPool;
var Shipit = require('../lib/shipit');
describe('Shipit', function () {
var shipit, stdout, stderr;
beforeEach(function () {
stdout = new stream.MockWritableStream();
stderr = new stream.MockWritableStream();
shipit = new Shipit({
stdout: stdout,
stderr: stderr,
environment: 'stage'
});
shipit.stage = 'stage';
});
describe('#initialize', function () {
beforeEach(function () {
sinon.stub(shipit, 'initSshPool').returns(shipit);
});
afterEach(function () {
shipit.initSshPool.restore();
});
it('should add stage and initialize shipit', function () {
shipit.initialize();
expect(shipit.initSshPool).to.be.called;
});
});
describe('#initSshPool', function () {
it('should initialize an ssh pool', function () {
shipit.config = {servers: ['deploy@my-server']};
shipit.initSshPool();
expect(shipit.pool).to.be.instanceOf(ConnectionPool);
expect(shipit.pool).to.have.deep.property('.connections[0].remote.user', 'deploy');
expect(shipit.pool).to.have.deep.property('.connections[0].remote.host', 'my-server');
});
});
describe('#initConfig', function () {
it('should initialize config', function () {
shipit.initConfig({default: {foo: 'bar'}, stage: {kung: 'foo'}});
expect(shipit.config).to.be.deep.equal({
branch: 'master',
keepReleases: 5,
foo: 'bar',
kung: 'foo',
shallowClone: false
});
});
});
describe('#local', function () {
it('should wrap and log to stdout', function () {
stdout.startCapture();
return shipit.local('echo "hello"').then(function (res) {
expect(stdout.capturedData).to.equal('@ hello\n');
expect(res).to.have.property('stdout');
expect(res).to.have.property('stderr');
expect(res).to.have.property('child');
});
});
});
describe('#remote', function () {
beforeEach(function () {
shipit.pool = {run: sinon.stub()};
});
it('should run command on pool', function () {
shipit.remote('my-command');
expect(shipit.pool.run).to.be.calledWith('my-command');
});
});
describe('#remoteCopy', function () {
beforeEach(function () {
shipit.pool = {copy: sinon.stub()};
});
it('should run command on pool', function () {
shipit.remoteCopy('src', 'dest');
expect(shipit.pool.copy).to.be.calledWith('src', 'dest');
});
it('should accept options for shipit.pool.copy', function () {
shipit.remoteCopy('src', 'dest', {
direction: 'remoteToLocal'
});
expect(shipit.pool.copy).to.be.calledWith('src', 'dest', {
direction: 'remoteToLocal',
ignores: [],
rsync: []
});
});
it('should support options specified in shipit.config', function () {
shipit.config = {
ignores: ['foo'],
rsync: ['--bar']
};
shipit.remoteCopy('src', 'dest', {
direction: 'remoteToLocal',
rsync: '--foo'
});
expect(shipit.pool.copy).to.be.calledWith('src', 'dest', {
direction: 'remoteToLocal',
ignores: ['foo'],
rsync: ['--bar']
});
});
it('should support options specified in options parameter', function () {
shipit.remoteCopy('src', 'dest', {
direction: 'remoteToLocal',
rsync: '--foo'
});
expect(shipit.pool.copy).to.be.calledWith('src', 'dest', {
direction: 'remoteToLocal',
ignores: [],
rsync: '--foo'
});
});
});
});