Fix review issues

This commit is contained in:
David Humphrey 2018-12-12 21:27:09 -05:00
parent af3815c54b
commit 16e6b3e1c9
1 changed files with 38 additions and 68 deletions

View File

@ -135,10 +135,6 @@ describe('fs.promises.link', function() {
}); });
}); });
describe('fs.promises.link', function() { describe('fs.promises.link', function() {
beforeEach(util.setup); beforeEach(util.setup);
afterEach(util.cleanup); afterEach(util.cleanup);
@ -148,74 +144,48 @@ describe('fs.promises.link', function() {
expect(fs.promises.link).to.be.a('function'); expect(fs.promises.link).to.be.a('function');
}); });
it('should create a link to an existing file', function(done) { it('should create a link to an existing file', function() {
var fs = util.fs(); var fs = util.fs().promises;
fs.open('/myfile', 'w+', function(error, fd) { return fs.writeFile('/myfile', 'data')
if(error) throw error; .then(() => fs.link('/myfile', '/myotherfile'))
.then(() => fs.stat('/myfile'))
.then(stats => {
var _oldstats = stats;
fs.close(fd, function(error) { return fs.stat('/myotherfile')
if(error) throw error; .then(stats => {
expect(stats.nlinks).to.equal(2);
fs.promises.link('/myfile', '/myotherfile').then(function(){ expect(stats.dev).to.equal(_oldstats.dev);
expect(stats.node).to.equal(_oldstats.node);
fs.stat('/myfile', function(error, result) { expect(stats.size).to.equal(_oldstats.size);
if(error) throw error; expect(stats.type).to.equal(_oldstats.type);
var _oldstats = result;
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(2);
expect(result.dev).to.equal(_oldstats.dev);
expect(result.node).to.equal(_oldstats.node);
expect(result.size).to.equal(_oldstats.size);
expect(result.type).to.equal(_oldstats.type);
done();
});
},
function(error){throw error;}
);
});
}); });
}); });
}); });
it('should create hard link to identical data node', function(done) { it('should create hard link to identical data node', function() {
var fs = util.fs(); var fs = util.fs().promises;
var contents = 'Hello World!'; var contents = 'Hello World!';
fs.writeFile('/file', contents, function(err) { return fs.writeFile('/file', contents)
if(err) throw err; .then(() => fs.link('/file', '/hlink'))
.then(() => fs.readFile('/file', 'utf8'))
.then(fileData => {
fs.link('/file', '/hlink', function(err) { return fs.readFile('/hlink', 'utf8')
if(err) throw err; .then(hlinkData => expect(fileData).to.equal(hlinkData));
fs.readFile('/file', 'utf8', function(err, fileData) {
if(err) throw err;
fs.readFile('/hlink', 'utf8', function(err, hlinkData) {
if(err) throw err;
expect(fileData).to.equal(hlinkData);
done();
});
});
});
}); });
}); });
it('should not allow links to a directory', function(done) { it('should not allow links to a directory', function() {
var fs = util.fs(); var fs = util.fs().promises;
fs.mkdir('/mydir', function(error) { return fs.mkdir('/mydir')
if(error) throw error; .then(() => fs.link('/mydir', '/mydirlink'))
.catch(error => {
fs.promises.link('/mydir', '/mydirlink', function(error) {
expect(error).to.exist; expect(error).to.exist;
expect(error.code).to.equal('EPERM'); expect(error.code).to.equal('EPERM');
done();
}); });
}); });
});
}); });