From 871c0fe88c78a0279ccebcad5f673eff108ae55e Mon Sep 17 00:00:00 2001 From: Thomas Nolte Date: Sun, 23 Sep 2018 22:42:39 -0400 Subject: [PATCH] added tests for fs.promises.chown() for check if function exists and updating gid/uid for a file --- tests/spec/fs.chown.spec.js | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/spec/fs.chown.spec.js b/tests/spec/fs.chown.spec.js index d6de220..017f77d 100644 --- a/tests/spec/fs.chown.spec.js +++ b/tests/spec/fs.chown.spec.js @@ -62,3 +62,51 @@ describe('fs.chown, fs.fchown', function() { }); }); }); + + +describe('fs.promises.chown', function(){ + beforeEach(util.setup); + afterEach(util.setup); + + it('should be a function', function(){ + var fs= util.fs(); + expect(fs.promises.chown).to.be.a('function'); + }); + + it('should allow updating uid and gid for a file', function(done) { + var fs = util.fs(); + + fs.open('/file', 'w', function(err, fd) { + if(err) throw err; + + fs.fchown(fd, 1001, 1001, function(err) { + if(err) throw err; + + fs.fstat(fd, function(err, stats){ + if(err) throw err; + + expect(stats.uid).to.equal(1001); + + fs.close(fd, function(){ + if(err) throw err; + + return fs.promises.chown('/file', 500, 500) + .then(()=>{ + fs.stat('/file', function(err, stats){ + if(err) throw err; + + expect(stats.uid).to.equal(500); + expect(stats.gid).to.equal(500); + + done(); + }); + }) + .catch((err)=>{ + throw(err) + }); + }); + }); + }) + }); + }); +});