2014-03-07 18:06:11 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-03-07 18:06:11 +00:00
|
|
|
describe('fs.stats', function() {
|
2014-02-21 01:56:53 +00:00
|
|
|
describe('#isFile()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFile).to.be.a('function');
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
|
2014-03-07 18:06:11 +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-03-07 23:10:02 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-07 23:10:02 +00:00
|
|
|
fs.fstat(fd, function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFile()).to.be.true;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if stats are for directory', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFile()).to.be.false;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if stats are for symbolic link', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.close(fd, function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFile()).to.be.false;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
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-03-07 23:10:02 +00:00
|
|
|
describe('#isDirectory()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isDirectory).to.be.a('function');
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if stats are for file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-07 23:10:02 +00:00
|
|
|
fs.fstat(fd, function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isDirectory()).to.be.false;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-07 23:10:02 +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-03-07 23:10:02 +00:00
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isDirectory()).to.be.true;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-03-07 23:10:02 +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-03-07 23:10:02 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.close(fd, function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isDirectory()).to.be.false;
|
2014-03-07 23:10:02 +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
|
|
|
|
|
|
|
describe('#isBlockDevice()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isBlockDevice).to.be.a('function');
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isBlockDevice()).to.be.false;
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
describe('#isCharacterDevice()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isCharacterDevice).to.be.a('function');
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isCharacterDevice()).to.be.false;
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
describe('#isSymbolicLink()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSymbolicLink).to.be.a('function');
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-07 23:10:02 +00:00
|
|
|
it('should return false if stats are for file', function(done) {
|
|
|
|
var fs = util.fs();
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-03-07 23:10:02 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-07 23:10:02 +00:00
|
|
|
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-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
2014-03-07 23:10:02 +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;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSymbolicLink()).to.be.false;
|
2014-03-07 23:10:02 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return true if stats are for symbolic link', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.close(fd, function(error, stats) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.lstat('/myfilelink', function(error, stats) {
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSymbolicLink()).to.be.true;
|
2014-03-07 23:10:02 +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
|
|
|
|
|
|
|
describe('#isFIFO()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFIFO).to.be.a('function');
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isFIFO()).to.be.false;
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
describe('#isSocket()', function() {
|
2014-03-07 18:06:11 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-02-21 01:56:53 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSocket).to.be.a('function');
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false', function() {
|
2014-03-07 23:10:02 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
fs.stat('/', function(error, stats) {
|
2014-02-21 01:56:53 +00:00
|
|
|
if(error) throw error;
|
2014-03-08 18:53:53 +00:00
|
|
|
expect(stats.isSocket()).to.be.false;
|
2014-02-21 01:56:53 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|
2014-03-07 18:06:11 +00:00
|
|
|
});
|
2014-03-07 23:10:02 +00:00
|
|
|
});
|