This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsync.spec.coffee
86 lines (67 loc) · 2.56 KB
/
rsync.spec.coffee
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
m = require('mochainon')
_ = require('lodash')
rsync = require('../lib/rsync')
mockFs = require('mock-fs')
filesystem = {}
filesystem['/.gitignore'] = '''
npm-debug.log
node_modules/
lib/*
!lib/include with space.txt
!lib/include\ with\ space.txt
!lib/include with space trail.txt\\
# comment
\\#notacomment
'''
assertCommand = (command, options) ->
expected = 'rsync -az'
if options.progress
expected += ' --progress'
expected += ' --rsh=\"ssh -p 22 -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no\"'
expected += ' --delete'
expected += " --rsync-path=\"\\$(which rsync) 1234 4567\""
expected += ' --include=\"lib/include with space.txt\" --include=\"lib/include with space trail.txt \"'
expected += ' --exclude=npm-debug.log --exclude=node_modules/ --exclude=lib/* --exclude=#notacomment'
if options.ignore?
expected += ' ' + _.map options.ignore, (pattern) ->
return "--exclude=#{pattern}"
.join(' ')
# node-rsync@0.4.0 bug - the single quote should normally not be escaped since it appears inside double quotes
expected += " . \"test@ssh.resindevice.io:/usr/src/app/a/b/\\` \\' @ ! \\$test \\\" end\""
m.chai.expect(command).to.equal(expected)
describe 'Rsync:', ->
defaultOpts =
username: 'test'
source: '/'
destination: "/usr/src/app/a/b/` ' @ ! $test \" end"
port: 22
host: 'ssh.resindevice.io'
'rsync-path': '$(which rsync) 1234 4567'
beforeEach ->
mockFs(filesystem)
afterEach ->
mockFs.restore()
it 'should throw if progress is not a boolean', ->
m.chai.expect ->
rsync.buildRsyncCommand(_.merge({}, defaultOpts, progress: 'true'))
.to.throw('Not a boolean: progress')
it 'should throw if ignore is not a string nor array', ->
m.chai.expect ->
rsync.buildRsyncCommand(_.merge({}, defaultOpts, ignore: 1234))
.to.throw('Not a string or array: ignore')
it 'should be able to set progress to true', ->
opts = _.merge({}, defaultOpts, progress: true)
command = rsync.buildRsyncCommand(opts)
assertCommand(command, opts)
it 'should be able to set progress to false', ->
opts = _.merge({}, defaultOpts, progress: false)
command = rsync.buildRsyncCommand(opts)
assertCommand(command, opts)
it 'should be able to exclute a single pattern', ->
opts = _.merge({}, defaultOpts, ignore: [ '.git' ])
command = rsync.buildRsyncCommand(opts)
assertCommand(command, opts)
it 'should be able to exclute a multiple patterns', ->
opts = _.merge({}, defaultOpts, ignore: [ '.git', 'node_modules' ])
command = rsync.buildRsyncCommand(opts)
assertCommand(command, opts)