Skip to content

Commit

Permalink
test: fix test-fs-symlink-dir-junction-relative
Browse files Browse the repository at this point in the history
  * The test no longer relies on being invoked from a particular
    working directory to function properly.
  * fs.symlink() and fs.symlinkSync() are both tested.
  * The test now cleans up after itself.

This commit fixes nodejs/node#126

PR-URL: nodejs/node#129
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
piscisaureus committed Dec 9, 2014
1 parent 8e272df commit 4efc02a
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions test/simple/test-fs-symlink-dir-junction-relative.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,48 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// Test creating and resolving relative junction or symbolic link

var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var completed = 0;
var expected_tests = 4;

// test creating and reading symbolic link
var linkData = path.join(common.fixturesDir, 'cycles');
var linkPath = path.join(common.tmpDir, 'cycles_link');
var relative = '../fixtures/cycles';
var expected_tests = 2;

// Delete previously created link
try {
fs.unlinkSync(linkPath);
} catch (e) {}
var linkPath1 = path.join(common.tmpDir, 'junction1');
var linkPath2 = path.join(common.tmpDir, 'junction2');
var linkTarget = path.join(common.fixturesDir);
var linkData = '../fixtures';

console.log('linkData: ' + linkData);
console.log('linkPath: ' + linkPath);
console.log('relative target: ' + relative)
// Prepare.
try { fs.mkdirSync(common.tmpDir); } catch (e) {}
try { fs.unlinkSync(linkPath1); } catch (e) {}
try { fs.unlinkSync(linkPath2); } catch (e) {}

fs.symlink(relative, linkPath, 'junction', function(err) {
// Test fs.symlink()
fs.symlink(linkData, linkPath1, 'junction', function(err) {
if (err) throw err;
completed++;
verifyLink(linkPath1);
});

fs.lstat(linkPath, function(err, stats) {
if (err) throw err;
assert.ok(stats.isSymbolicLink());
completed++;
// Test fs.symlinkSync()
fs.symlinkSync(linkData, linkPath2, 'junction');
verifyLink(linkPath2);

fs.readlink(linkPath, function(err, destination) {
if (err) throw err;
assert.equal(path.resolve(destination), linkData);
completed++;
function verifyLink(linkPath) {
var stats = fs.lstatSync(linkPath);
assert.ok(stats.isSymbolicLink());

fs.unlink(linkPath, function(err) {
if (err) throw err;
assert(!fs.existsSync(linkPath));
assert(fs.existsSync(linkData));
completed++;
});
});
});
});
var data1 = fs.readFileSync(linkPath + '/x.txt', 'ascii');
var data2 = fs.readFileSync(linkTarget + '/x.txt', 'ascii');
assert.strictEqual(data1, data2);

// Clean up.
fs.unlinkSync(linkPath);

completed++;
}

process.on('exit', function() {
assert.equal(completed, expected_tests);
Expand Down

0 comments on commit 4efc02a

Please sign in to comment.