Skip to content

Commit

Permalink
fs: added tests for util file preprocessSymlinkDestination
Browse files Browse the repository at this point in the history
PR-URL: nodejs#27468
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
rpgeeganage authored and Trott committed May 1, 2019
1 parent 5f68489 commit 64284aa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/parallel/test-internal-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const fs = require('internal/fs/utils');

// Valid encodings and no args should not throw.
Expand All @@ -12,3 +13,41 @@ common.expectsError(
() => fs.assertEncoding('foo'),
{ code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError }
);

// Test junction symlinks
{
const pathString = 'c:\\test1';
const linkPathString = '\\test2';

const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
pathString,
'junction',
linkPathString
);

if (process.platform === 'win32') {
assert.strictEqual(/^\\\\\?\\/.test(preprocessSymlinkDestination), true);
} else {
assert.strictEqual(preprocessSymlinkDestination, pathString);
}
}

// Test none junction symlinks
{
const pathString = 'c:\\test1';
const linkPathString = '\\test2';

const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
pathString,
undefined,
linkPathString
);

if (process.platform === 'win32') {
// There should not be any forward slashes
assert.strictEqual(
/\//.test(preprocessSymlinkDestination), false);
} else {
assert.strictEqual(preprocessSymlinkDestination, pathString);
}
}

0 comments on commit 64284aa

Please sign in to comment.