-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
executable file
·164 lines (150 loc) · 3.65 KB
/
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
var tape = require('tape')
var parseBenny = require('./parseBenny')
var jsonBenny = require('./jsonBenny')
tape('BennyFile Tests: parses', function (t) {
var parsedBenny = parseBenny(`
VIA ubuntu:precise
GO rm -f /etc/resolv.conf && echo '8.8.8.8' > /etc/resolv.conf
GO apt-get update
GO apt-get install -y python-software-properties && \\
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \\
apt-get update
GO apt-get install -y g++-4.8 g++-4.8-multilib gcc-4.8-multilib && \\
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
GO foo \\
bar \\
baz
TO ./start.js /root/start.js
TO "./start.js" /root/start.js
TO " a b c " 'd e f'
TO foo\\ bar.js baz
`)
var expected = [{
type: 'via',
image: 'ubuntu',
version: 'precise',
path: null
}, {
type: 'go',
command: 'rm -f /etc/resolv.conf && echo \'8.8.8.8\' > /etc/resolv.conf'
}, {
type: 'go',
command: 'apt-get update'
}, {
type: 'go',
command: 'apt-get install -y python-software-properties && add-apt-repository -y ppa:ubuntu-toolchain-r/test && apt-get update'
}, {
type: 'go',
command: 'apt-get install -y g++-4.8 g++-4.8-multilib gcc-4.8-multilib && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50'
}, {
type: 'go',
command: 'foo bar baz'
}, {
type: 'to',
from: './start.js',
to: '/root/start.js'
}, {
type: 'to',
from: './start.js',
to: '/root/start.js'
}, {
type: 'to',
from: ' a b c ',
to: 'd e f'
}, {
type: 'to',
from: 'foo bar.js',
to: 'baz'
}]
t.same(parsedBenny.length, expected.length)
for (var i = 0; i < parsedBenny.length; i++) {
t.same(parsedBenny[i], expected[i])
}
t.end()
})
tape('BennyFile Tests: force', function (t) {
t.same(parseBenny('FORCE GO foo'), [{type: 'go', command: 'foo', force: true}])
t.end()
})
tape('BennyFile Tests: other from', function (t) {
t.same(parseBenny('VIA ./path'), [{type: 'via', image: null, version: null, path: './path'}])
t.same(parseBenny('VIA "./path space"'), [{type: 'via', image: null, version: null, path: './path space'}])
t.end()
})
tape('BennyFile Tests: do', function (t) {
t.same(parseBenny('DO foo=bar\nDO foo'), [{
type: 'do',
key: 'foo',
value: 'bar'
}, {
type: 'do',
key: 'foo',
value: null
}])
t.end()
})
tape('BennyFile Tests: in', function (t) {
t.same(parseBenny('IN key value'), [{
type: 'in',
env: [{
key: 'key',
value: 'value'
}]
}])
t.same(parseBenny('IN key=value'), [{
type: 'in',
env: [{
key: 'key',
value: 'value'
}]
}])
t.same(parseBenny('IN key1=value1 key2=value2'), [{
type: 'in',
env: [{
key: 'key1',
value: 'value1'
}, {
key: 'key2',
value: 'value2'
}]
}])
t.end()
})
tape('BennyFile Tests: jsonBenny Object', function (t) {
t.same(jsonBenny([{type: 'via', image: 'arch'}]), 'VIA arch\n')
var input = [{
type: 'via',
path: './foo'
}, {
type: 'do',
key: 'foo',
value: 'bar'
}, {
type: 'go',
command: 'echo hello'
}, {
type: 'to',
from: 'a',
to: 'b'
}, {
type: 'in',
env: [{
key: 'hello',
value: 'world'
}, {
key: 'key',
value: 'bunch of spaces'
}]
}]
t.same(jsonBenny(input), 'VIA "./foo"\nDO foo="bar"\nGO echo hello\nTO "a" "b"\nIN hello="world" key="bunch of spaces"\n')
t.same(noNull(parseBenny(jsonBenny(input))), input)
t.end()
})
function noNull (inp) {
inp.forEach(function (i) {
Object.keys(i).forEach(function (k) {
if (i[k] === null) delete i[k]
})
})
return inp
}