Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 01bc213

Browse files
committed
fix: fix scpCopyFromRemote & scpCopyToRemote
Fixes #178
1 parent be1d621 commit 01bc213

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

packages/ssh-pool/src/Connection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ class Connection {
387387

388388
return results.reduce(
389389
(aggregate, result) => ({
390-
stdout: Buffer.concat([aggregate.stdout, result.stdout]),
391-
stderr: Buffer.concat([aggregate.stderr, result.stderr]),
390+
stdout: String(aggregate.stdout) + String(result.stdout),
391+
stderr: String(aggregate.stderr) + String(result.stderr),
392392
children: [...aggregate.children, result.child],
393393
}),
394394
{
395-
stdout: Buffer.from([]),
396-
stderr: Buffer.from([]),
395+
stdout: '',
396+
stderr: '',
397397
children: [],
398398
},
399399
)

packages/ssh-pool/src/Connection.test.js

+7-24
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jest.mock('tmp')
1111

1212
describe('Connection', () => {
1313
beforeEach(() => {
14+
exec.mockClear()
1415
util.deprecateV3 = jest.fn()
1516
__setPaths__({ rsync: '/bin/rsync' })
1617
})
@@ -48,22 +49,20 @@ describe('Connection', () => {
4849
await connection.run('my-command -x', { cwd: '/root' })
4950

5051
expect(exec).toHaveBeenCalledWith(
51-
'ssh user@host "my-command -x"',
52+
'ssh user@host "cd /root > /dev/null; my-command -x; cd - > /dev/null"',
5253
{
53-
cwd: '/root',
5454
maxBuffer: 1024000,
5555
},
5656
expect.any(Function),
5757
)
5858
})
5959

6060
it('should escape double quotes', async () => {
61-
await connection.run('echo "ok"', { cwd: '/root' })
61+
await connection.run('echo "ok"')
6262

6363
expect(exec).toHaveBeenCalledWith(
6464
'ssh user@host "echo \\"ok\\""',
6565
{
66-
cwd: '/root',
6766
maxBuffer: 1024000,
6867
},
6968
expect.any(Function),
@@ -76,26 +75,12 @@ describe('Connection', () => {
7675
expect(result.stderr.toString()).toBe('stderr')
7776
})
7877

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-
9278
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 })
9480

9581
expect(exec).toHaveBeenCalledWith(
9682
'ssh -tt user@host "sudo my-command -x"',
9783
{
98-
cwd: '/root',
9984
maxBuffer: 1024000,
10085
},
10186
expect.any(Function),
@@ -168,7 +153,7 @@ describe('Connection', () => {
168153
)
169154
})
170155

171-
it.only('should log output', async () => {
156+
it('should log output', async () => {
172157
const log = jest.fn()
173158
connection = new Connection({
174159
remote: 'user@host',
@@ -209,25 +194,23 @@ describe('Connection', () => {
209194
})
210195

211196
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 })
213198

214199
expect(exec).toHaveBeenCalledWith(
215200
'ssh -tt user@host "sudo -u test my-command -x"',
216201
{
217-
cwd: '/root',
218202
maxBuffer: 1000 * 1024,
219203
},
220204
expect.any(Function),
221205
)
222206
})
223207

224208
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 })
226210

227211
expect(exec).toHaveBeenCalledWith(
228212
'ssh -tt user@host "sudo -u test my-command -x"',
229213
{
230-
cwd: '/root',
231214
maxBuffer: 1000 * 1024,
232215
},
233216
expect.any(Function),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello

packages/ssh-pool/tests/integration.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
13
const sshPool = require('../src')
24

35
describe('ssh-pool', () => {
@@ -21,4 +23,15 @@ describe('ssh-pool', () => {
2123
const [{ stdout: second }] = await pool.run("echo '$USER'")
2224
expect(second).toBe('$USER\n')
2325
})
26+
27+
it(
28+
'should copy to remote',
29+
async () => {
30+
await pool.scpCopyToRemote(
31+
path.resolve(__dirname, '__fixtures__/test.txt'),
32+
'./',
33+
)
34+
},
35+
20000,
36+
)
2437
})

0 commit comments

Comments
 (0)