summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2014-12-09 21:15:32 +0100
committerBert Belder <bertbelder@gmail.com>2014-12-09 21:16:29 +0100
commit4efc02a582cb0f85ea43524dd80ce4953f972511 (patch)
tree91914841ce639a9be75428aa0b0aeb9ec3b18e2c
parent8e272dffa24df43b4139768d9c389eb7d239d8d7 (diff)
downloadnode-new-4efc02a582cb0f85ea43524dd80ce4953f972511.tar.gz
test: fix test-fs-symlink-dir-junction-relative
* 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 https://github.com/iojs/io.js/issues/126 PR-URL: https://github.com/iojs/io.js/pull/129 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
-rw-r--r--test/simple/test-fs-symlink-dir-junction-relative.js62
1 files changed, 30 insertions, 32 deletions
diff --git a/test/simple/test-fs-symlink-dir-junction-relative.js b/test/simple/test-fs-symlink-dir-junction-relative.js
index d54938a770..c598d2e926 100644
--- a/test/simple/test-fs-symlink-dir-junction-relative.js
+++ b/test/simple/test-fs-symlink-dir-junction-relative.js
@@ -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);