@@ -11,6 +11,7 @@ jest.mock('tmp')
11
11
12
12
describe ( 'Connection' , ( ) => {
13
13
beforeEach ( ( ) => {
14
+ exec . mockClear ( )
14
15
util . deprecateV3 = jest . fn ( )
15
16
__setPaths__ ( { rsync : '/bin/rsync' } )
16
17
} )
@@ -48,22 +49,20 @@ describe('Connection', () => {
48
49
await connection . run ( 'my-command -x' , { cwd : '/root' } )
49
50
50
51
expect ( exec ) . toHaveBeenCalledWith (
51
- 'ssh user@host "my-command -x"' ,
52
+ 'ssh user@host "cd /root > /dev/null; my-command -x; cd - > /dev/null "' ,
52
53
{
53
- cwd : '/root' ,
54
54
maxBuffer : 1024000 ,
55
55
} ,
56
56
expect . any ( Function ) ,
57
57
)
58
58
} )
59
59
60
60
it ( 'should escape double quotes' , async ( ) => {
61
- await connection . run ( 'echo "ok"' , { cwd : '/root' } )
61
+ await connection . run ( 'echo "ok"' )
62
62
63
63
expect ( exec ) . toHaveBeenCalledWith (
64
64
'ssh user@host "echo \\"ok\\""' ,
65
65
{
66
- cwd : '/root' ,
67
66
maxBuffer : 1024000 ,
68
67
} ,
69
68
expect . any ( Function ) ,
@@ -76,26 +75,12 @@ describe('Connection', () => {
76
75
expect ( result . stderr . toString ( ) ) . toBe ( 'stderr' )
77
76
} )
78
77
79
- it ( 'should handle sudo' , async ( ) => {
80
- await connection . run ( 'sudo my-command -x' , { cwd : '/root' } )
81
-
82
- expect ( exec ) . toHaveBeenCalledWith (
83
- 'ssh -tt user@host "sudo my-command -x"' ,
84
- {
85
- cwd : '/root' ,
86
- maxBuffer : 1024000 ,
87
- } ,
88
- expect . any ( Function ) ,
89
- )
90
- } )
91
-
92
78
it ( 'should handle tty' , async ( ) => {
93
- await connection . run ( 'sudo my-command -x' , { cwd : '/root' , tty : true } )
79
+ await connection . run ( 'sudo my-command -x' , { tty : true } )
94
80
95
81
expect ( exec ) . toHaveBeenCalledWith (
96
82
'ssh -tt user@host "sudo my-command -x"' ,
97
83
{
98
- cwd : '/root' ,
99
84
maxBuffer : 1024000 ,
100
85
} ,
101
86
expect . any ( Function ) ,
@@ -168,7 +153,7 @@ describe('Connection', () => {
168
153
)
169
154
} )
170
155
171
- it . only ( 'should log output' , async ( ) => {
156
+ it ( 'should log output' , async ( ) => {
172
157
const log = jest . fn ( )
173
158
connection = new Connection ( {
174
159
remote : 'user@host' ,
@@ -209,25 +194,23 @@ describe('Connection', () => {
209
194
} )
210
195
211
196
it ( 'should handle sudo as user correctly' , async ( ) => {
212
- await connection . run ( 'my-command -x' , { cwd : '/root' , tty : true } )
197
+ await connection . run ( 'my-command -x' , { tty : true } )
213
198
214
199
expect ( exec ) . toHaveBeenCalledWith (
215
200
'ssh -tt user@host "sudo -u test my-command -x"' ,
216
201
{
217
- cwd : '/root' ,
218
202
maxBuffer : 1000 * 1024 ,
219
203
} ,
220
204
expect . any ( Function ) ,
221
205
)
222
206
} )
223
207
224
208
it ( 'should handle sudo as user without double sudo' , ( ) => {
225
- connection . run ( 'sudo my-command -x' , { cwd : '/root' } )
209
+ connection . run ( 'sudo my-command -x' , { tty : true } )
226
210
227
211
expect ( exec ) . toHaveBeenCalledWith (
228
212
'ssh -tt user@host "sudo -u test my-command -x"' ,
229
213
{
230
- cwd : '/root' ,
231
214
maxBuffer : 1000 * 1024 ,
232
215
} ,
233
216
expect . any ( Function ) ,
0 commit comments