From 87230ce1e391b50a776ab4caeb443d82b505f274 Mon Sep 17 00:00:00 2001 From: Daniel Bogomazov Date: Tue, 9 Oct 2018 12:59:17 -0400 Subject: [PATCH] Fix #405 - Added tests for chmod and fchmod using Promises (#458) * Added tests for chmod and fchmod using Promises * Remove unrelated files from pull request * Fixed spelling mistake * Removed redundant catch blocks --- tests/spec/fs.chmod.spec.js | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/spec/fs.chmod.spec.js b/tests/spec/fs.chmod.spec.js index 800f18f..090d98b 100644 --- a/tests/spec/fs.chmod.spec.js +++ b/tests/spec/fs.chmod.spec.js @@ -71,3 +71,67 @@ describe('fs.chmod, fs.fchmod', function() { }); }); }); + +describe('fsPromise.chmod', function() { + beforeEach(util.setup); + afterEach(util.setup); + + it('should be a function', function() { + var fsPromise = util.fs().promises; + expect(typeof fsPromise.chmod).to.equal('function'); + }); + + it('should return a promise', function() { + var fsPromise = util.fs().promises; + expect(fsPromise.chmod()).to.be.a('Promise'); + }); + + it('should allow for updating mode of a given file', function() { + var fsPromise = util.fs().promises; + + return fsPromise.open('/file', 'w') + .then( () => { + return fsPromise.chmod('/file', 0o444); + }) + .then( () => { + return fsPromise.stat('/file'); + }) + .then( stats => { + expect(stats.mode & 0o444).to.equal(0o444); + }) + .catch( err => { throw err; }); + }); +}); + +describe('fsPromise.fchmod', function() { + beforeEach(util.setup); + afterEach(util.setup); + + it('should be a function', function() { + var fsPromise = util.fs().promises; + expect(typeof fsPromise.fchmod).to.equal('function'); + }); + + it('should be a promise', function() { + var fsPromise = util.fs().promises; + expect(fsPromise.fchmod()).to.be.a('Promise'); + }); + + it('should allow for updating mode of a given file', function() { + var fsPromise = util.fs().promises; + var fdesc; + + return fsPromise.open('/file', 'w') + .then( fd => { + fdesc = fd; + return fsPromise.fchmod(fd, 0o777); + }) + .then( () => { + return fsPromise.fstat(fdesc); + }) + .then( stats => { + expect(stats.mode & 0o777).to.equal(0o777); + }) + .catch( err => { throw err; }); + }); +}); \ No newline at end of file