node/test/parallel/test-fs-symlink.js
Rich Trott 1c57845118 test: fix flaky test for symlinks
If the symlink portion of the test was being skipped due to a
combination of OS support and user privileges, then an assertion would
always fail. This fixes that problem, improves assertion error reporting
and splits the test to make it clear that it is a test for links and
symlinks.

Fixes: https://github.com/nodejs/node/issues/3311
PR-URL: https://github.com/nodejs/node/pull/3418
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-10-20 09:20:21 -07:00

51 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const exec = require('child_process').exec;
var linkTime;
var fileTime;
if (common.isWindows) {
// On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges.
exec('whoami /priv', function(err, o) {
if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) {
console.log('1..0 # Skipped: insufficient privileges');
return;
}
});
}
common.refreshTmpDir();
// test creating and reading symbolic link
const linkData = path.join(common.fixturesDir, '/cycles/root.js');
const linkPath = path.join(common.tmpDir, 'symlink1.js');
fs.symlink(linkData, linkPath, function(err) {
if (err) throw err;
fs.lstat(linkPath, common.mustCall(function(err, stats) {
if (err) throw err;
linkTime = stats.mtime.getTime();
}));
fs.stat(linkPath, common.mustCall(function(err, stats) {
if (err) throw err;
fileTime = stats.mtime.getTime();
}));
fs.readlink(linkPath, common.mustCall(function(err, destination) {
if (err) throw err;
assert.equal(destination, linkData);
}));
});
process.on('exit', function() {
assert.notStrictEqual(linkTime, fileTime);
});