filer/tests/spec/fs.stats.spec.js

297 lines
7.7 KiB
JavaScript
Raw Normal View History

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-05-23 20:53:50 +00:00
describe('fs.stats', function() {
describe('#isFile()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
2014-05-23 20:53:50 +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-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-05-23 20:53:50 +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-05-23 20:53:50 +00:00
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFile()).to.be.false;
done();
});
2014-05-23 20:53:50 +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-05-23 20:53:50 +00:00
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error, stats) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.symlink('/myfile', '/myfilelink', function(error) {
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-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
describe('#isDirectory()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
2014-05-23 20:53:50 +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-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-05-23 20:53:50 +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-05-23 20:53:50 +00:00
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isDirectory()).to.be.true;
done();
});
2014-05-23 20:53:50 +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-05-23 20:53:50 +00:00
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error, stats) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.symlink('/myfile', '/myfilelink', function(error) {
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-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
describe('#isBlockDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
});
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;
done();
});
2014-05-23 20:53:50 +00:00
});
});
2014-05-23 20:53:50 +00:00
describe('#isCharacterDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
});
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;
done();
});
2014-05-23 20:53:50 +00:00
});
});
2014-05-23 20:53:50 +00:00
describe('#isSymbolicLink()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
2014-05-23 20:53:50 +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-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.isSymbolicLink()).to.be.false;
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-05-23 20:53:50 +00:00
it('should return true if stats are for symbolic link', function(done) {
var fs = util.fs();
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) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.symlink('/myfile', '/myfilelink', function(error) {
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-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
describe('#isFIFO()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
2014-05-23 20:53:50 +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;
done();
});
});
2014-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
describe('#isSocket()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
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');
done();
});
2014-05-23 20:53:50 +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;
done();
});
});
});
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();
});
});
});
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();
});
});
});
});
2014-05-23 20:53:50 +00:00
});