2019-02-12 19:49:20 +00:00
|
|
|
'use strict';
|
|
|
|
const util = require('../lib/test-utils.js');
|
|
|
|
const expect = require('chai').expect;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('fs.lstat', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should be a function', function() {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fs = util.fs();
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(typeof fs.lstat).to.equal('function');
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return an error if path does not exist', function(done) {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fs = util.fs();
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/tmp', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
2018-07-15 17:25:35 +00:00
|
|
|
expect(error.code).to.equal('ENOENT');
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return a stat object if path is not a symbolic link', function(done) {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fs = util.fs();
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(result.isDirectory()).to.be.true;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return a stat object if path is a symbolic link', function(done) {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fs = util.fs();
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.symlink('/', '/mylink', function(error) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/mylink', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(result.isSymbolicLink()).to.be.true;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-02-08 03:36:50 +00:00
|
|
|
|
|
|
|
it('should have a mode (full node) when stat\'d with lstat', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.writeFile('/file', 'data', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
fs.symlink('/file', '/symlink', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
fs.lstat('/symlink', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
// We should build and return a full node object, complete with
|
|
|
|
// calculated mode, which should be a SYMLINK and the default file permissions.
|
|
|
|
expect(stats.mode).to.equal(fs.constants.S_IFLNK | 0o644);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2018-10-10 01:17:25 +00:00
|
|
|
|
2018-09-25 02:47:52 +00:00
|
|
|
describe('fs.promises.lstat', () => {
|
2018-10-10 01:17:25 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should return an error if path does not exist', () => {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fsPromises = util.fs().promises;
|
2018-10-10 01:17:25 +00:00
|
|
|
|
|
|
|
return fsPromises.lstat('/tmp')
|
|
|
|
.catch( error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-25 02:47:52 +00:00
|
|
|
it('should return a stat object if path is not a symbolic link', () => {
|
2019-02-12 19:49:20 +00:00
|
|
|
const fsPromises = util.fs().promises;
|
|
|
|
|
2018-09-25 02:47:52 +00:00
|
|
|
return fsPromises.lstat('/')
|
|
|
|
.then(result => {
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result.isDirectory()).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|