2018-06-28 23:26:08 +00:00
|
|
|
var Path = require('../../src').Path;
|
2014-05-23 20:53:50 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('fs.stats', function() {
|
|
|
|
describe('#isFile()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isFile).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return true if stats are for file', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.fstat(fd, function(error, stats) {
|
|
|
|
expect(stats.isFile()).to.be.true;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return false if stats are for directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isFile()).to.be.false;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return false if stats are for symbolic link', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.close(fd, function(error, stats) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2018-07-26 22:17:05 +00:00
|
|
|
expect(stats).to.exist;
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
|
|
|
expect(stats.isFile()).to.be.false;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isDirectory()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isDirectory).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return false if stats are for file', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.fstat(fd, function(error, stats) {
|
|
|
|
expect(stats.isDirectory()).to.be.false;
|
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return true if stats are for directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isDirectory()).to.be.true;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return false if stats are for symbolic link', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
2018-07-26 22:17:05 +00:00
|
|
|
fs.close(fd, function(error) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
|
|
|
expect(stats.isDirectory()).to.be.false;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isBlockDevice()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isBlockDevice).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should return false', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isBlockDevice()).to.be.false;
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isCharacterDevice()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isCharacterDevice).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should return false', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isCharacterDevice()).to.be.false;
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isSymbolicLink()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isSymbolicLink).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return false if stats are for file', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.fstat(fd, function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSymbolicLink()).to.be.false;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if stats are for directory', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isSymbolicLink()).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should return true if stats are for symbolic link', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-03-07 23:10:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
2018-07-26 22:17:05 +00:00
|
|
|
fs.close(fd, function(error) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
2014-03-07 23:10:02 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
|
|
|
expect(stats.isSymbolicLink()).to.be.true;
|
|
|
|
done();
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isFIFO()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isFIFO).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should return false', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isFIFO()).to.be.false;
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('#isSocket()', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should be a function', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isSocket).to.be.a('function');
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2017-05-21 22:11:12 +00:00
|
|
|
it('should return false', function(done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
expect(stats.isSocket()).to.be.false;
|
2017-05-21 22:11:12 +00:00
|
|
|
done();
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2018-05-26 21:45:28 +00:00
|
|
|
|
|
|
|
describe('generated name property', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should correct return name for a file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var filepath = '/a';
|
|
|
|
|
|
|
|
fs.writeFile(filepath, 'data', function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.stat(filepath, function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(stats.name).to.equal(Path.basename(filepath));
|
|
|
|
done();
|
|
|
|
});
|
2018-07-15 17:25:35 +00:00
|
|
|
});
|
2018-05-26 21:45:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correct return name for an fd', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var filepath = '/a';
|
|
|
|
|
|
|
|
fs.open(filepath, 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fstat(fd, function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(stats.name).to.equal(Path.basename(filepath));
|
|
|
|
done();
|
|
|
|
});
|
2018-07-15 17:25:35 +00:00
|
|
|
});
|
2018-05-26 21:45:28 +00:00
|
|
|
});
|
2018-07-15 17:25:35 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|