From 914ba8b473d80d0d2bbbd775080c813d7607728a Mon Sep 17 00:00:00 2001 From: rscotchmer Date: Tue, 26 Feb 2019 11:40:27 -0500 Subject: [PATCH 1/2] added test to fs.readlink.spec.js --- tests/spec/fs.readlink.spec.js | 53 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/tests/spec/fs.readlink.spec.js b/tests/spec/fs.readlink.spec.js index 1c96dc7..f97129f 100644 --- a/tests/spec/fs.readlink.spec.js +++ b/tests/spec/fs.readlink.spec.js @@ -3,42 +3,57 @@ const util = require('../lib/test-utils.js'); const expect = require('chai').expect; -describe('fs.readlink', function() { +describe('fs.readlink', function () { beforeEach(util.setup); afterEach(util.cleanup); - it('should be a function', function() { + it('should be a function', function () { const fs = util.fs(); expect(fs.readlink).to.be.a('function'); }); - it('should return an error if part of the parent destination path does not exist', function(done) { + it('should return an error if part of the parent destination path does not exist', function (done) { const fs = util.fs(); - fs.readlink('/tmp/mydir', function(error) { + fs.readlink('/tmp/mydir', function (error) { expect(error).to.exist; expect(error.code).to.equal('ENOENT'); done(); }); }); - it('should return an error if the path is not a symbolic link', function(done) { + it('should return an error if the path is not a symbolic link', function (done) { const fs = util.fs(); - fs.readlink('/', function(error) { + fs.readlink('/', function (error) { expect(error).to.exist; expect(error.code).to.equal('ENOENT'); done(); }); }); - it('should return the contents of a symbolic link', function(done) { + it('should return an error if the path is not a symbolic link', function (done) { const fs = util.fs(); - fs.symlink('/', '/myfile', function(error) { - if(error) throw error; + fs.mkdir('/tmp', function (error) { + if (error) throw error; - fs.readlink('/myfile', function(error, result) { + fs.readlink('/tmp', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + + }); + }); + + it('should return the contents of a symbolic link', function (done) { + const fs = util.fs(); + + fs.symlink('/', '/myfile', function (error) { + if (error) throw error; + + fs.readlink('/myfile', function (error, result) { expect(error).not.to.exist; expect(result).to.equal('/'); done(); @@ -46,24 +61,24 @@ describe('fs.readlink', function() { }); }); - it('should allow relative paths, but resolve to the dstpath', function(done) { + it('should allow relative paths, but resolve to the dstpath', function (done) { const fs = util.fs(); const contents = 'contents'; - fs.mkdir('/dir', function(error) { - if(error) throw error; + fs.mkdir('/dir', function (error) { + if (error) throw error; - fs.writeFile('/file', contents, function(error) { - if(error) throw error; + fs.writeFile('/file', contents, function (error) { + if (error) throw error; - fs.symlink('../file', '/dir/symlink', function(error) { - if(error) throw error; + fs.symlink('../file', '/dir/symlink', function (error) { + if (error) throw error; - fs.readlink('/dir/symlink', function(error, result) { + fs.readlink('/dir/symlink', function (error, result) { expect(error).not.to.exist; expect(result).to.equal('../file'); - fs.readFile('/dir/symlink', 'utf8', function(error, data) { + fs.readFile('/dir/symlink', 'utf8', function (error, data) { expect(error).not.to.exist; expect(data).to.equal(contents); done(); From ee5679460183df83e15df1f094ef8ac06850c23f Mon Sep 17 00:00:00 2001 From: Charles M Drani Date: Wed, 27 Feb 2019 09:56:11 -0700 Subject: [PATCH 2/2] add test for fs.open with wx flag for existing file (#745) * add test for fs.open with wx flag for existing file * update implementation and open spec to throw EEXIST --- src/filesystem/implementation.js | 2 +- tests/spec/fs.open.spec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 725097b..b5a8f8b 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -620,7 +620,7 @@ function open_file(context, path, flags, mode, callback) { directoryData = result; if(directoryData.hasOwnProperty(name)) { if(flags.includes(O_EXCLUSIVE)) { - callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); + callback(new Errors.EEXIST('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); } else { directoryEntry = directoryData[name]; if(directoryEntry.type === NODE_TYPE_DIRECTORY && flags.includes(O_WRITE)) { diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index edb7bc8..819b1ba 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -47,6 +47,23 @@ describe('fs.open', function() { }); }); + it('should return an error when flagged for write and the path exists', function(done) { + var fs = util.fs(); + + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.writeFile('/tmp/file', 'data', function(error) { + if(error) throw error; + fs.open('/tmp/file', 'wx', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal('EEXIST'); + expect(result).not.to.exist; + done(); + }); + }); + }); + }); + it('should return an error when flagged for append and the path is a directory', function(done) { var fs = util.fs();