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;
|
|
|
|
expect(typeof stats.isFile).to.equal('function');
|
|
|
|
});
|
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) {
|
|
|
|
expect(stats.isFile()).to.equal(true);
|
|
|
|
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;
|
|
|
|
expect(stats.isFile()).to.equal(false);
|
|
|
|
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) {
|
|
|
|
expect(stats.isFile()).to.equal(false);
|
|
|
|
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;
|
|
|
|
expect(typeof stats.isDirectory).to.equal('function');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
expect(stats.isDirectory()).to.equal(false);
|
|
|
|
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-07 23:10:02 +00:00
|
|
|
expect(stats.isDirectory()).to.equal(true);
|
|
|
|
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) {
|
|
|
|
expect(stats.isDirectory()).to.equal(false);
|
|
|
|
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-07 23:10:02 +00:00
|
|
|
expect(typeof stats.isBlockDevice).to.equal('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-07 23:10:02 +00:00
|
|
|
expect(stats.isBlockDevice()).to.equal(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-07 23:10:02 +00:00
|
|
|
expect(typeof stats.isCharacterDevice).to.equal('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-07 23:10:02 +00:00
|
|
|
expect(stats.isCharacterDevice()).to.equal(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-07 23:10:02 +00:00
|
|
|
expect(typeof stats.isSymbolicLink).to.equal('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) {
|
|
|
|
expect(stats.isSymbolicLink()).to.equal(false);
|
|
|
|
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;
|
|
|
|
expect(stats.isSymbolicLink()).to.equal(false);
|
|
|
|
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) {
|
|
|
|
expect(stats.isSymbolicLink()).to.equal(true);
|
|
|
|
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-07 23:10:02 +00:00
|
|
|
expect(typeof stats.isFIFO).to.equal('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-07 23:10:02 +00:00
|
|
|
expect(stats.isFIFO()).to.equal(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-07 23:10:02 +00:00
|
|
|
expect(typeof stats.isSocket).to.equal('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-07 23:10:02 +00:00
|
|
|
expect(stats.isSocket()).to.equal(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
|
|
|
});
|