Skip to content
Permalink
Browse files

fs: added tests for util file preprocessSymlinkDestination

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 Trott committed Apr 28, 2019
1 parent 5f68489 commit 64284aad388d836cb1de6b0cd59a70d2fb282d5e
Showing with 39 additions and 0 deletions.
  1. +39 −0 test/parallel/test-internal-fs.js
@@ -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.
@@ -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.
You can’t perform that action at this time.