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: #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 targos committed May 1, 2019
1 parent 33fead3 commit 7be1e0a
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 7be1e0a

Please sign in to comment.