Skip to content

Commit 9db57fe

Browse files
author
Dimitar Markov
committed
Add a demo test
1 parent f176a9c commit 9db57fe

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/test-sftp.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,23 @@ setup('WriteStream', mustCall((client, server) => {
719719
writer.end();
720720
}));
721721

722+
setup('environment', { SSH2NODETEST: 'foo' }, mustCall((client, server) => {
723+
const path_ = '/tmp/foo.txt';
724+
const handle_ = Buffer.from('node.js');
725+
const pflags_ = (OPEN_MODE.TRUNC | OPEN_MODE.CREAT | OPEN_MODE.WRITE);
726+
server.on('OPEN', mustCall((id, path, pflags) => {
727+
assert(id === 0, `Wrong request id: ${id}`);
728+
assert(path === path_, `Wrong path: ${path}`);
729+
assert(pflags === pflags_, `Wrong flags: ${flagsToHuman(pflags)}`);
730+
server.handle(id, handle_);
731+
server.end();
732+
}));
733+
client.open(path_, 'w', mustCall((err, handle) => {
734+
assert(!err, `Unexpected open() error: ${err}`);
735+
assert.deepStrictEqual(handle, handle_, 'handle mismatch');
736+
}));
737+
}));
738+
722739
{
723740
const { client, server } = setup_(
724741
'SFTP server aborts with exit-status',
@@ -757,7 +774,12 @@ setup('WriteStream', mustCall((client, server) => {
757774

758775

759776
// =============================================================================
760-
function setup(title, cb) {
777+
function setup(title, env, cb) {
778+
if (typeof env === 'function') {
779+
cb = env;
780+
env = undefined;
781+
}
782+
761783
const { client, server } = setupSimple(DEBUG, title);
762784
let clientSFTP;
763785
let serverSFTP;
@@ -768,7 +790,7 @@ function setup(title, cb) {
768790
}, 2);
769791

770792
client.on('ready', mustCall(() => {
771-
client.sftp(mustCall((err, sftp) => {
793+
client.sftp(env, mustCall((err, sftp) => {
772794
assert(!err, `[${title}] Unexpected client sftp start error: ${err}`);
773795
sftp.on('close', mustCall(() => {
774796
client.end();

0 commit comments

Comments
 (0)