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

260 lines
6.8 KiB
JavaScript
Raw Permalink Normal View History

2014-05-23 20:53:50 +00:00
var Filer = require('../..');
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();
});
});
});
2014-05-23 20:53:50 +00:00
});