Get tests to run

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-05-23 16:53:50 -04:00
parent 38627f95d6
commit 4ab41c4aea
52 changed files with 4099 additions and 4107 deletions

View File

@ -1,32 +1,33 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('trailing slashes in path names, issue 105', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('trailing slashes in path names, issue 105', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should deal with trailing slashes properly, path == path/', function(done) {
var fs = util.fs();
it('should deal with trailing slashes properly, path == path/', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(err) {
fs.mkdir('/tmp', function(err) {
if(err) throw err;
fs.mkdir('/tmp/foo', function(err) {
if(err) throw err;
fs.mkdir('/tmp/foo', function(err) {
// Without trailing slash
fs.readdir('/tmp', function(err, result1) {
if(err) throw err;
expect(result1).to.exist;
expect(result1.length).to.equal(1);
// Without trailing slash
fs.readdir('/tmp', function(err, result1) {
// With trailing slash
fs.readdir('/tmp/', function(err, result2) {
if(err) throw err;
expect(result1).to.exist;
expect(result1.length).to.equal(1);
// With trailing slash
fs.readdir('/tmp/', function(err, result2) {
if(err) throw err;
expect(result2).to.exist;
expect(result2[0]).to.equal('foo');
expect(result1).to.deep.equal(result2);
done();
});
expect(result2).to.exist;
expect(result2[0]).to.equal('foo');
expect(result1).to.deep.equal(result2);
done();
});
});
});

View File

@ -1,28 +1,29 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.writeFile truncation - issue 106', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.writeFile truncation - issue 106', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should truncate an existing file', function(done) {
var fs = util.fs();
var filename = '/test';
it('should truncate an existing file', function(done) {
var fs = util.fs();
var filename = '/test';
fs.writeFile(filename, '1', function(err) {
fs.writeFile(filename, '1', function(err) {
if(err) throw err;
fs.stat(filename, function(err, stats) {
if(err) throw err;
expect(stats.size).to.equal(1);
fs.stat(filename, function(err, stats) {
fs.writeFile(filename, '', function(err) {
if(err) throw err;
expect(stats.size).to.equal(1);
fs.writeFile(filename, '', function(err) {
fs.stat(filename, function(err, stats) {
if(err) throw err;
fs.stat(filename, function(err, stats) {
if(err) throw err;
expect(stats.size).to.equal(0);
done();
});
expect(stats.size).to.equal(0);
done();
});
});
});

View File

@ -52,7 +52,7 @@
}
// Allow passing FS flags on query string
var flags = global.filerArgs && global.filerArgs.flags) ?
var flags = global.filerArgs && global.filerArgs.flags ?
global.filerArgs.flags : 'FORMAT';
// Create a file system and wait for it to get setup

View File

@ -1,136 +1,136 @@
define(["Filer"], function(Filer) {
var Filer = require('../..');
var expect = require('chai').expect;
describe("Filer.Errors", function() {
it("has expected errors", function() {
expect(Filer.Errors).to.exist;
describe("Filer.Errors", function() {
it("has expected errors", function() {
expect(Filer.Errors).to.exist;
// By ctor
expect(Filer.Errors.UNKNOWN).to.be.a('function');
expect(Filer.Errors.OK).to.be.a('function');
expect(Filer.Errors.EOF).to.be.a('function');
expect(Filer.Errors.EADDRINFO).to.be.a('function');
expect(Filer.Errors.EACCES).to.be.a('function');
expect(Filer.Errors.EAGAIN).to.be.a('function');
expect(Filer.Errors.EADDRINUSE).to.be.a('function');
expect(Filer.Errors.EADDRNOTAVAIL).to.be.a('function');
expect(Filer.Errors.EAFNOSUPPORT).to.be.a('function');
expect(Filer.Errors.EALREADY).to.be.a('function');
expect(Filer.Errors.EBADF).to.be.a('function');
expect(Filer.Errors.EBUSY).to.be.a('function');
expect(Filer.Errors.ECONNABORTED).to.be.a('function');
expect(Filer.Errors.ECONNREFUSED).to.be.a('function');
expect(Filer.Errors.ECONNRESET).to.be.a('function');
expect(Filer.Errors.EDESTADDRREQ).to.be.a('function');
expect(Filer.Errors.EFAULT).to.be.a('function');
expect(Filer.Errors.EHOSTUNREACH).to.be.a('function');
expect(Filer.Errors.EINTR).to.be.a('function');
expect(Filer.Errors.EINVAL).to.be.a('function');
expect(Filer.Errors.EISCONN).to.be.a('function');
expect(Filer.Errors.EMFILE).to.be.a('function');
expect(Filer.Errors.EMSGSIZE).to.be.a('function');
expect(Filer.Errors.ENETDOWN).to.be.a('function');
expect(Filer.Errors.ENETUNREACH).to.be.a('function');
expect(Filer.Errors.ENFILE).to.be.a('function');
expect(Filer.Errors.ENOBUFS).to.be.a('function');
expect(Filer.Errors.ENOMEM).to.be.a('function');
expect(Filer.Errors.ENOTDIR).to.be.a('function');
expect(Filer.Errors.EISDIR).to.be.a('function');
expect(Filer.Errors.ENONET).to.be.a('function');
expect(Filer.Errors.ENOTCONN).to.be.a('function');
expect(Filer.Errors.ENOTSOCK).to.be.a('function');
expect(Filer.Errors.ENOTSUP).to.be.a('function');
expect(Filer.Errors.ENOENT).to.be.a('function');
expect(Filer.Errors.ENOSYS).to.be.a('function');
expect(Filer.Errors.EPIPE).to.be.a('function');
expect(Filer.Errors.EPROTO).to.be.a('function');
expect(Filer.Errors.EPROTONOSUPPORT).to.be.a('function');
expect(Filer.Errors.EPROTOTYPE).to.be.a('function');
expect(Filer.Errors.ETIMEDOUT).to.be.a('function');
expect(Filer.Errors.ECHARSET).to.be.a('function');
expect(Filer.Errors.EAIFAMNOSUPPORT).to.be.a('function');
expect(Filer.Errors.EAISERVICE).to.be.a('function');
expect(Filer.Errors.EAISOCKTYPE).to.be.a('function');
expect(Filer.Errors.ESHUTDOWN).to.be.a('function');
expect(Filer.Errors.EEXIST).to.be.a('function');
expect(Filer.Errors.ESRCH).to.be.a('function');
expect(Filer.Errors.ENAMETOOLONG).to.be.a('function');
expect(Filer.Errors.EPERM).to.be.a('function');
expect(Filer.Errors.ELOOP).to.be.a('function');
expect(Filer.Errors.EXDEV).to.be.a('function');
expect(Filer.Errors.ENOTEMPTY).to.be.a('function');
expect(Filer.Errors.ENOSPC).to.be.a('function');
expect(Filer.Errors.EIO).to.be.a('function');
expect(Filer.Errors.EROFS).to.be.a('function');
expect(Filer.Errors.ENODEV).to.be.a('function');
expect(Filer.Errors.ESPIPE).to.be.a('function');
expect(Filer.Errors.ECANCELED).to.be.a('function');
expect(Filer.Errors.ENOTMOUNTED).to.be.a('function');
expect(Filer.Errors.EFILESYSTEMERROR).to.be.a('function');
expect(Filer.Errors.ENOATTR).to.be.a('function');
// By ctor
expect(Filer.Errors.UNKNOWN).to.be.a('function');
expect(Filer.Errors.OK).to.be.a('function');
expect(Filer.Errors.EOF).to.be.a('function');
expect(Filer.Errors.EADDRINFO).to.be.a('function');
expect(Filer.Errors.EACCES).to.be.a('function');
expect(Filer.Errors.EAGAIN).to.be.a('function');
expect(Filer.Errors.EADDRINUSE).to.be.a('function');
expect(Filer.Errors.EADDRNOTAVAIL).to.be.a('function');
expect(Filer.Errors.EAFNOSUPPORT).to.be.a('function');
expect(Filer.Errors.EALREADY).to.be.a('function');
expect(Filer.Errors.EBADF).to.be.a('function');
expect(Filer.Errors.EBUSY).to.be.a('function');
expect(Filer.Errors.ECONNABORTED).to.be.a('function');
expect(Filer.Errors.ECONNREFUSED).to.be.a('function');
expect(Filer.Errors.ECONNRESET).to.be.a('function');
expect(Filer.Errors.EDESTADDRREQ).to.be.a('function');
expect(Filer.Errors.EFAULT).to.be.a('function');
expect(Filer.Errors.EHOSTUNREACH).to.be.a('function');
expect(Filer.Errors.EINTR).to.be.a('function');
expect(Filer.Errors.EINVAL).to.be.a('function');
expect(Filer.Errors.EISCONN).to.be.a('function');
expect(Filer.Errors.EMFILE).to.be.a('function');
expect(Filer.Errors.EMSGSIZE).to.be.a('function');
expect(Filer.Errors.ENETDOWN).to.be.a('function');
expect(Filer.Errors.ENETUNREACH).to.be.a('function');
expect(Filer.Errors.ENFILE).to.be.a('function');
expect(Filer.Errors.ENOBUFS).to.be.a('function');
expect(Filer.Errors.ENOMEM).to.be.a('function');
expect(Filer.Errors.ENOTDIR).to.be.a('function');
expect(Filer.Errors.EISDIR).to.be.a('function');
expect(Filer.Errors.ENONET).to.be.a('function');
expect(Filer.Errors.ENOTCONN).to.be.a('function');
expect(Filer.Errors.ENOTSOCK).to.be.a('function');
expect(Filer.Errors.ENOTSUP).to.be.a('function');
expect(Filer.Errors.ENOENT).to.be.a('function');
expect(Filer.Errors.ENOSYS).to.be.a('function');
expect(Filer.Errors.EPIPE).to.be.a('function');
expect(Filer.Errors.EPROTO).to.be.a('function');
expect(Filer.Errors.EPROTONOSUPPORT).to.be.a('function');
expect(Filer.Errors.EPROTOTYPE).to.be.a('function');
expect(Filer.Errors.ETIMEDOUT).to.be.a('function');
expect(Filer.Errors.ECHARSET).to.be.a('function');
expect(Filer.Errors.EAIFAMNOSUPPORT).to.be.a('function');
expect(Filer.Errors.EAISERVICE).to.be.a('function');
expect(Filer.Errors.EAISOCKTYPE).to.be.a('function');
expect(Filer.Errors.ESHUTDOWN).to.be.a('function');
expect(Filer.Errors.EEXIST).to.be.a('function');
expect(Filer.Errors.ESRCH).to.be.a('function');
expect(Filer.Errors.ENAMETOOLONG).to.be.a('function');
expect(Filer.Errors.EPERM).to.be.a('function');
expect(Filer.Errors.ELOOP).to.be.a('function');
expect(Filer.Errors.EXDEV).to.be.a('function');
expect(Filer.Errors.ENOTEMPTY).to.be.a('function');
expect(Filer.Errors.ENOSPC).to.be.a('function');
expect(Filer.Errors.EIO).to.be.a('function');
expect(Filer.Errors.EROFS).to.be.a('function');
expect(Filer.Errors.ENODEV).to.be.a('function');
expect(Filer.Errors.ESPIPE).to.be.a('function');
expect(Filer.Errors.ECANCELED).to.be.a('function');
expect(Filer.Errors.ENOTMOUNTED).to.be.a('function');
expect(Filer.Errors.EFILESYSTEMERROR).to.be.a('function');
expect(Filer.Errors.ENOATTR).to.be.a('function');
// By errno
expect(Filer.Errors[-1]).to.equal(Filer.Errors.UNKNOWN);
expect(Filer.Errors[0]).to.equal(Filer.Errors.OK);
expect(Filer.Errors[1]).to.equal(Filer.Errors.EOF);
expect(Filer.Errors[2]).to.equal(Filer.Errors.EADDRINFO);
expect(Filer.Errors[3]).to.equal(Filer.Errors.EACCES);
expect(Filer.Errors[4]).to.equal(Filer.Errors.EAGAIN);
expect(Filer.Errors[5]).to.equal(Filer.Errors.EADDRINUSE);
expect(Filer.Errors[6]).to.equal(Filer.Errors.EADDRNOTAVAIL);
expect(Filer.Errors[7]).to.equal(Filer.Errors.EAFNOSUPPORT);
expect(Filer.Errors[8]).to.equal(Filer.Errors.EALREADY);
expect(Filer.Errors[9]).to.equal(Filer.Errors.EBADF);
expect(Filer.Errors[10]).to.equal(Filer.Errors.EBUSY);
expect(Filer.Errors[11]).to.equal(Filer.Errors.ECONNABORTED);
expect(Filer.Errors[12]).to.equal(Filer.Errors.ECONNREFUSED);
expect(Filer.Errors[13]).to.equal(Filer.Errors.ECONNRESET);
expect(Filer.Errors[14]).to.equal(Filer.Errors.EDESTADDRREQ);
expect(Filer.Errors[15]).to.equal(Filer.Errors.EFAULT);
expect(Filer.Errors[16]).to.equal(Filer.Errors.EHOSTUNREACH);
expect(Filer.Errors[17]).to.equal(Filer.Errors.EINTR);
expect(Filer.Errors[18]).to.equal(Filer.Errors.EINVAL);
expect(Filer.Errors[19]).to.equal(Filer.Errors.EISCONN);
expect(Filer.Errors[20]).to.equal(Filer.Errors.EMFILE);
expect(Filer.Errors[21]).to.equal(Filer.Errors.EMSGSIZE);
expect(Filer.Errors[22]).to.equal(Filer.Errors.ENETDOWN);
expect(Filer.Errors[23]).to.equal(Filer.Errors.ENETUNREACH);
expect(Filer.Errors[24]).to.equal(Filer.Errors.ENFILE);
expect(Filer.Errors[25]).to.equal(Filer.Errors.ENOBUFS);
expect(Filer.Errors[26]).to.equal(Filer.Errors.ENOMEM);
expect(Filer.Errors[27]).to.equal(Filer.Errors.ENOTDIR);
expect(Filer.Errors[28]).to.equal(Filer.Errors.EISDIR);
expect(Filer.Errors[29]).to.equal(Filer.Errors.ENONET);
expect(Filer.Errors[31]).to.equal(Filer.Errors.ENOTCONN);
expect(Filer.Errors[32]).to.equal(Filer.Errors.ENOTSOCK);
expect(Filer.Errors[33]).to.equal(Filer.Errors.ENOTSUP);
expect(Filer.Errors[34]).to.equal(Filer.Errors.ENOENT);
expect(Filer.Errors[35]).to.equal(Filer.Errors.ENOSYS);
expect(Filer.Errors[36]).to.equal(Filer.Errors.EPIPE);
expect(Filer.Errors[37]).to.equal(Filer.Errors.EPROTO);
expect(Filer.Errors[38]).to.equal(Filer.Errors.EPROTONOSUPPORT);
expect(Filer.Errors[39]).to.equal(Filer.Errors.EPROTOTYPE);
expect(Filer.Errors[40]).to.equal(Filer.Errors.ETIMEDOUT);
expect(Filer.Errors[41]).to.equal(Filer.Errors.ECHARSET);
expect(Filer.Errors[42]).to.equal(Filer.Errors.EAIFAMNOSUPPORT);
expect(Filer.Errors[44]).to.equal(Filer.Errors.EAISERVICE);
expect(Filer.Errors[45]).to.equal(Filer.Errors.EAISOCKTYPE);
expect(Filer.Errors[46]).to.equal(Filer.Errors.ESHUTDOWN);
expect(Filer.Errors[47]).to.equal(Filer.Errors.EEXIST);
expect(Filer.Errors[48]).to.equal(Filer.Errors.ESRCH);
expect(Filer.Errors[49]).to.equal(Filer.Errors.ENAMETOOLONG);
expect(Filer.Errors[50]).to.equal(Filer.Errors.EPERM);
expect(Filer.Errors[51]).to.equal(Filer.Errors.ELOOP);
expect(Filer.Errors[52]).to.equal(Filer.Errors.EXDEV);
expect(Filer.Errors[53]).to.equal(Filer.Errors.ENOTEMPTY);
expect(Filer.Errors[54]).to.equal(Filer.Errors.ENOSPC);
expect(Filer.Errors[55]).to.equal(Filer.Errors.EIO);
expect(Filer.Errors[56]).to.equal(Filer.Errors.EROFS);
expect(Filer.Errors[57]).to.equal(Filer.Errors.ENODEV);
expect(Filer.Errors[58]).to.equal(Filer.Errors.ESPIPE);
expect(Filer.Errors[59]).to.equal(Filer.Errors.ECANCELED);
expect(Filer.Errors[1000]).to.equal(Filer.Errors.ENOTMOUNTED);
expect(Filer.Errors[1001]).to.equal(Filer.Errors.EFILESYSTEMERROR);
expect(Filer.Errors[1002]).to.equal(Filer.Errors.ENOATTR);
});
// By errno
expect(Filer.Errors[-1]).to.equal(Filer.Errors.UNKNOWN);
expect(Filer.Errors[0]).to.equal(Filer.Errors.OK);
expect(Filer.Errors[1]).to.equal(Filer.Errors.EOF);
expect(Filer.Errors[2]).to.equal(Filer.Errors.EADDRINFO);
expect(Filer.Errors[3]).to.equal(Filer.Errors.EACCES);
expect(Filer.Errors[4]).to.equal(Filer.Errors.EAGAIN);
expect(Filer.Errors[5]).to.equal(Filer.Errors.EADDRINUSE);
expect(Filer.Errors[6]).to.equal(Filer.Errors.EADDRNOTAVAIL);
expect(Filer.Errors[7]).to.equal(Filer.Errors.EAFNOSUPPORT);
expect(Filer.Errors[8]).to.equal(Filer.Errors.EALREADY);
expect(Filer.Errors[9]).to.equal(Filer.Errors.EBADF);
expect(Filer.Errors[10]).to.equal(Filer.Errors.EBUSY);
expect(Filer.Errors[11]).to.equal(Filer.Errors.ECONNABORTED);
expect(Filer.Errors[12]).to.equal(Filer.Errors.ECONNREFUSED);
expect(Filer.Errors[13]).to.equal(Filer.Errors.ECONNRESET);
expect(Filer.Errors[14]).to.equal(Filer.Errors.EDESTADDRREQ);
expect(Filer.Errors[15]).to.equal(Filer.Errors.EFAULT);
expect(Filer.Errors[16]).to.equal(Filer.Errors.EHOSTUNREACH);
expect(Filer.Errors[17]).to.equal(Filer.Errors.EINTR);
expect(Filer.Errors[18]).to.equal(Filer.Errors.EINVAL);
expect(Filer.Errors[19]).to.equal(Filer.Errors.EISCONN);
expect(Filer.Errors[20]).to.equal(Filer.Errors.EMFILE);
expect(Filer.Errors[21]).to.equal(Filer.Errors.EMSGSIZE);
expect(Filer.Errors[22]).to.equal(Filer.Errors.ENETDOWN);
expect(Filer.Errors[23]).to.equal(Filer.Errors.ENETUNREACH);
expect(Filer.Errors[24]).to.equal(Filer.Errors.ENFILE);
expect(Filer.Errors[25]).to.equal(Filer.Errors.ENOBUFS);
expect(Filer.Errors[26]).to.equal(Filer.Errors.ENOMEM);
expect(Filer.Errors[27]).to.equal(Filer.Errors.ENOTDIR);
expect(Filer.Errors[28]).to.equal(Filer.Errors.EISDIR);
expect(Filer.Errors[29]).to.equal(Filer.Errors.ENONET);
expect(Filer.Errors[31]).to.equal(Filer.Errors.ENOTCONN);
expect(Filer.Errors[32]).to.equal(Filer.Errors.ENOTSOCK);
expect(Filer.Errors[33]).to.equal(Filer.Errors.ENOTSUP);
expect(Filer.Errors[34]).to.equal(Filer.Errors.ENOENT);
expect(Filer.Errors[35]).to.equal(Filer.Errors.ENOSYS);
expect(Filer.Errors[36]).to.equal(Filer.Errors.EPIPE);
expect(Filer.Errors[37]).to.equal(Filer.Errors.EPROTO);
expect(Filer.Errors[38]).to.equal(Filer.Errors.EPROTONOSUPPORT);
expect(Filer.Errors[39]).to.equal(Filer.Errors.EPROTOTYPE);
expect(Filer.Errors[40]).to.equal(Filer.Errors.ETIMEDOUT);
expect(Filer.Errors[41]).to.equal(Filer.Errors.ECHARSET);
expect(Filer.Errors[42]).to.equal(Filer.Errors.EAIFAMNOSUPPORT);
expect(Filer.Errors[44]).to.equal(Filer.Errors.EAISERVICE);
expect(Filer.Errors[45]).to.equal(Filer.Errors.EAISOCKTYPE);
expect(Filer.Errors[46]).to.equal(Filer.Errors.ESHUTDOWN);
expect(Filer.Errors[47]).to.equal(Filer.Errors.EEXIST);
expect(Filer.Errors[48]).to.equal(Filer.Errors.ESRCH);
expect(Filer.Errors[49]).to.equal(Filer.Errors.ENAMETOOLONG);
expect(Filer.Errors[50]).to.equal(Filer.Errors.EPERM);
expect(Filer.Errors[51]).to.equal(Filer.Errors.ELOOP);
expect(Filer.Errors[52]).to.equal(Filer.Errors.EXDEV);
expect(Filer.Errors[53]).to.equal(Filer.Errors.ENOTEMPTY);
expect(Filer.Errors[54]).to.equal(Filer.Errors.ENOSPC);
expect(Filer.Errors[55]).to.equal(Filer.Errors.EIO);
expect(Filer.Errors[56]).to.equal(Filer.Errors.EROFS);
expect(Filer.Errors[57]).to.equal(Filer.Errors.ENODEV);
expect(Filer.Errors[58]).to.equal(Filer.Errors.ESPIPE);
expect(Filer.Errors[59]).to.equal(Filer.Errors.ECANCELED);
expect(Filer.Errors[1000]).to.equal(Filer.Errors.ENOTMOUNTED);
expect(Filer.Errors[1001]).to.equal(Filer.Errors.EFILESYSTEMERROR);
expect(Filer.Errors[1002]).to.equal(Filer.Errors.ENOATTR);
});
});

View File

@ -1,13 +1,12 @@
define(["Filer"], function(Filer) {
var Filer = require('../..');
var expect = require('chai');
describe("Filer", function() {
it("is defined", function() {
expect(typeof Filer).not.to.equal(undefined);
});
it("has FileSystem constructor", function() {
expect(typeof Filer.FileSystem).to.equal('function');
});
describe("Filer", function() {
it("is defined", function() {
expect(typeof Filer).not.to.equal(undefined);
});
});
it("has FileSystem constructor", function() {
expect(typeof Filer.FileSystem).to.equal('function');
});
});

View File

@ -1,129 +1,130 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.appendFile', function() {
beforeEach(function(done) {
util.setup(function() {
var fs = util.fs();
fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) {
if(error) throw error;
done();
});
});
});
afterEach(util.cleanup);
it('should be a function', function() {
describe('fs.appendFile', function() {
beforeEach(function(done) {
util.setup(function() {
var fs = util.fs();
expect(fs.appendFile).to.be.a('function');
});
it('should append a utf8 file without specifying utf8 in appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.appendFile('/myfile', more, function(error) {
fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
done();
});
});
});
afterEach(util.cleanup);
it('should append a utf8 file with "utf8" option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
it('should be a function', function() {
var fs = util.fs();
expect(fs.appendFile).to.be.a('function');
});
fs.appendFile('/myfile', more, 'utf8', function(error) {
if(error) throw error;
it('should append a utf8 file without specifying utf8 in appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
fs.appendFile('/myfile', more, function(error) {
if(error) throw error;
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
it('should append a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var binary = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var more = " Appended.";
var binary2 = new Uint8Array([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
var binary3 = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
fs.writeFile('/mybinaryfile', binary, function(error) {
if(error) throw error;
fs.appendFile('/mybinaryfile', binary2, function(error) {
if(error) throw error;
fs.readFile('/mybinaryfile', 'ascii', function(error, data) {
expect(error).not.to.exist;
expect(data).to.deep.equal(binary3);
done();
});
});
});
});
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
fs.appendFile('/myFileLink', more, 'utf8', function (error) {
if (error) throw error;
fs.readFile('/myFileLink', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
});
it('should work when file does not exist, and create the file', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) {
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
fs.readFile('/newfile', 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
it('should append a utf8 file with "utf8" option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.appendFile('/myfile', more, 'utf8', function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
it('should append a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var binary = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var more = " Appended.";
var binary2 = new Uint8Array([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
var binary3 = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
fs.writeFile('/mybinaryfile', binary, function(error) {
if(error) throw error;
fs.appendFile('/mybinaryfile', binary2, function(error) {
if(error) throw error;
fs.readFile('/mybinaryfile', 'ascii', function(error, data) {
expect(error).not.to.exist;
expect(data).to.deep.equal(binary3);
done();
});
});
});
});
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
fs.appendFile('/myFileLink', more, 'utf8', function (error) {
if (error) throw error;
fs.readFile('/myFileLink', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
});
it('should work when file does not exist, and create the file', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) {
expect(error).not.to.exist;
fs.readFile('/newfile', 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
});

View File

@ -1,30 +1,30 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.close', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.close', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.close).to.equal('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.close).to.equal('function');
});
it('should release the file descriptor', function(done) {
var buffer = new Uint8Array(0);
var fs = util.fs();
it('should release the file descriptor', function(done) {
var buffer = new Uint8Array(0);
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
expect(error).to.exist;
done();
});
var fd = result;
fs.close(fd, function(error) {
fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
expect(error).to.exist;
done();
});
});
});
});
});

View File

@ -1,59 +1,60 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.exists', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.exists', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.exists).to.equal('function');
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.exists).to.equal('function');
});
it('should return false if path does not exist', function(done) {
var fs = util.fs();
fs.exists('/tmp', function(result) {
expect(result).to.be.false;
done();
});
});
it('should return false if path does not exist', function(done) {
var fs = util.fs();
it('should return true if path exists', function(done) {
var fs = util.fs();
fs.exists('/tmp', function(result) {
expect(result).to.be.false;
done();
});
});
fs.open('/myfile', 'w', function(err, fd) {
if(err) throw err;
it('should return true if path exists', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(err, fd) {
fs.close(fd, function(err) {
if(err) throw err;
fs.close(fd, function(err) {
if(err) throw err;
fs.exists('/myfile', function(result) {
expect(result).to.be.true;
done();
});
});
});
});
fs.exists('/myfile', function(result) {
it('should follow symbolic links and return true for the resulting path', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.exists('/myfilelink', function(result) {
expect(result).to.be.true;
done();
});
});
});
});
it('should follow symbolic links and return true for the resulting path', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.exists('/myfilelink', function(result) {
expect(result).to.be.true;
done();
});
});
});
});
});
});
});

View File

@ -1,67 +1,40 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.link', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.link', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.link).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.link).to.be.a('function');
});
it('should create a link to an existing file', function(done) {
var fs = util.fs();
it('should create a link to an existing file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.close(fd, function(error) {
fs.link('/myfile', '/myotherfile', function(error) {
if(error) throw error;
fs.link('/myfile', '/myotherfile', function(error) {
fs.stat('/myfile', function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
var _oldstats = result;
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(2);
expect(result.dev).to.equal(_oldstats.dev);
expect(result.node).to.equal(_oldstats.node);
expect(result.size).to.equal(_oldstats.size);
expect(result.type).to.equal(_oldstats.type);
done();
});
});
});
});
});
});
it('should not follow symbolic links', function(done) {
var fs = util.fs();
fs.stat('/', function (error, result) {
if (error) throw error;
var _oldstats = result;
fs.symlink('/', '/myfileLink', function (error) {
if (error) throw error;
fs.link('/myfileLink', '/myotherfile', function (error) {
if (error) throw error;
fs.lstat('/myfileLink', function (error, result) {
if (error) throw error;
var _linkstats = result;
fs.lstat('/myotherfile', function (error, result) {
expect(error).not.to.exist;
expect(result.dev).to.equal(_linkstats.dev);
expect(result.node).to.equal(_linkstats.node);
expect(result.size).to.equal(_linkstats.size);
expect(result.type).to.equal(_linkstats.type);
expect(result.nlinks).to.equal(2);
done();
});
var _oldstats = result;
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(2);
expect(result.dev).to.equal(_oldstats.dev);
expect(result.node).to.equal(_oldstats.node);
expect(result.size).to.equal(_oldstats.size);
expect(result.type).to.equal(_oldstats.type);
done();
});
});
});
@ -69,4 +42,31 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
it('should not follow symbolic links', function(done) {
var fs = util.fs();
fs.stat('/', function (error, result) {
if (error) throw error;
var _oldstats = result;
fs.symlink('/', '/myfileLink', function (error) {
if (error) throw error;
fs.link('/myfileLink', '/myotherfile', function (error) {
if (error) throw error;
fs.lstat('/myfileLink', function (error, result) {
if (error) throw error;
var _linkstats = result;
fs.lstat('/myotherfile', function (error, result) {
expect(error).not.to.exist;
expect(result.dev).to.equal(_linkstats.dev);
expect(result.node).to.equal(_linkstats.node);
expect(result.size).to.equal(_linkstats.size);
expect(result.type).to.equal(_linkstats.type);
expect(result.nlinks).to.equal(2);
done();
});
});
});
});
});
});
});

View File

@ -1,157 +1,41 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.lseek', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.lseek', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.lseek).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.lseek).to.be.a('function');
});
it('should not follow symbolic links', function(done) {
var fs = util.fs();
it('should not follow symbolic links', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function (error, fd) {
fs.open('/myfile', 'w', function (error, fd) {
if (error) throw error;
fs.close(fd, function (error) {
if (error) throw error;
fs.close(fd, function (error) {
fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
fs.symlink('/myfile', '/myFileLink', function (error) {
fs.rename('/myFileLink', '/myOtherFileLink', function (error) {
if (error) throw error;
fs.rename('/myFileLink', '/myOtherFileLink', function (error) {
if (error) throw error;
fs.stat('/myfile', function (error, result) {
expect(error).not.to.exist;
fs.lstat('/myFileLink', function (error, result) {
expect(error).to.exist;
fs.stat('/myOtherFileLink', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
done();
});
});
});
});
});
});
});
});
it('should set the current position if whence is SET', function(done) {
var fs = util.fs();
var offset = 3;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.lseek(fd, offset, 'SET', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset);
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + buffer.length);
var expected = new Uint8Array([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
});
});
});
});
});
});
it('should update the current position if whence is CUR', function(done) {
var fs = util.fs();
var offset = -2;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(2 * buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.lseek(fd, offset, 'CUR', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset + buffer.length);
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
});
});
});
});
});
});
it('should update the current position if whence is END', function(done) {
var fs = util.fs();
var offset = 5;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer;
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd1 = result;
fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd2 = result;
fs.lseek(fd2, offset, 'END', function(error, result) {
fs.stat('/myfile', function (error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset + buffer.length);
fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.lstat('/myFileLink', function (error, result) {
expect(error).to.exist;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
result_buffer = new Uint8Array(result.size);
fs.read(fd2, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
fs.stat('/myOtherFileLink', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
done();
});
});
});
@ -161,4 +45,120 @@ define(["Filer", "util"], function(Filer, util) {
});
});
it('should set the current position if whence is SET', function(done) {
var fs = util.fs();
var offset = 3;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.lseek(fd, offset, 'SET', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset);
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + buffer.length);
var expected = new Uint8Array([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
});
});
});
});
});
});
it('should update the current position if whence is CUR', function(done) {
var fs = util.fs();
var offset = -2;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(2 * buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.lseek(fd, offset, 'CUR', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset + buffer.length);
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
});
});
});
});
});
});
it('should update the current position if whence is END', function(done) {
var fs = util.fs();
var offset = 5;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer;
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd1 = result;
fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd2 = result;
fs.lseek(fd2, offset, 'END', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(offset + buffer.length);
fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
result_buffer = new Uint8Array(result.size);
fs.read(fd2, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
});
});
});
});
});
});
});
});

View File

@ -1,51 +1,51 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.lstat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.lstat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.lstat).to.equal('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.lstat).to.equal('function');
});
it('should return an error if path does not exist', function(done) {
var fs = util.fs();
var _error, _result;
it('should return an error if path does not exist', function(done) {
var fs = util.fs();
var _error, _result;
fs.lstat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
it('should return a stat object if path is not a symbolic link', function(done) {
var fs = util.fs();
fs.lstat('/', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
it('should return a stat object if path is a symbolic link', function(done) {
var fs = util.fs();
fs.symlink('/', '/mylink', function(error) {
if(error) throw error;
fs.lstat('/mylink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('SYMLINK');
done();
});
});
fs.lstat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
});
it('should return a stat object if path is not a symbolic link', function(done) {
var fs = util.fs();
fs.lstat('/', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
it('should return a stat object if path is a symbolic link', function(done) {
var fs = util.fs();
fs.symlink('/', '/mylink', function(error) {
if(error) throw error;
fs.lstat('/mylink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('SYMLINK');
done();
});
});
});
});

View File

@ -1,49 +1,49 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.mkdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.mkdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.mkdir).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.mkdir).to.be.a('function');
});
it('should return an error if part of the parent path does not exist', function(done) {
var fs = util.fs();
it('should return an error if part of the parent path does not exist', function(done) {
var fs = util.fs();
fs.mkdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return an error if the path already exists', function(done) {
var fs = util.fs();
fs.mkdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
done();
});
});
it('should make a new directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
fs.stat('/tmp', function(error, stats) {
expect(error).not.to.exist;
expect(stats).to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
fs.mkdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
});
it('should return an error if the path already exists', function(done) {
var fs = util.fs();
fs.mkdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
done();
});
});
it('should make a new directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
fs.stat('/tmp', function(error, stats) {
expect(error).not.to.exist;
expect(stats).to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
});
});

View File

@ -1,80 +1,81 @@
define(["Filer", "util"], function(Filer, util) {
describe('fs.mknod', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function(done) {
var fs = util.fs();
expect(fs.mknod).to.be.a('function');
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.mknod', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function(done) {
var fs = util.fs();
expect(fs.mknod).to.be.a('function');
done();
});
it('should return an error if part of the parent path does not exist', function(done) {
var fs = util.fs();
fs.mknod('/dir/mydir', 'DIRECTORY', function(error) {
expect(error.code).to.equal('ENOENT');
done();
});
it('should return an error if part of the parent path does not exist', function(done) {
var fs = util.fs();
fs.mknod('/dir/mydir', 'DIRECTORY', function(error) {
expect(error.code).to.equal('ENOENT');
done();
});
});
it('should return an error if path already exists', function(done) {
var fs = util.fs();
fs.mknod('/', 'DIRECTORY', function(error) {
expect(error.code).to.equal('EEXIST');
done();
});
});
it('should return an error if the parent node is not a directory', function(done) {
var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error, result) {
if(error) throw error;
fs.mknod('/file/myfile', 'FILE', function(error, result) {
expect(error.code).to.equal('ENOTDIR');
done();
});
});
});
it('should return an error if the mode provided is not DIRECTORY or FILE', function(done) {
var fs = util.fs();
fs.mknod('/symlink', 'SYMLINK', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
it('should make a new directory', function(done) {
var fs = util.fs();
fs.mknod('/dir', 'DIRECTORY', function(error) {
if(error) throw error;
fs.stat('/dir', function(error, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
});
it('should make a new file', function(done) {
var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error, result) {
if(error) throw error;
fs.stat('/file', function(error, result) {
expect(error).not.to.exist;
expect(result.type).to.equal('FILE');
done();
});
});
});
});
});
it('should return an error if path already exists', function(done) {
var fs = util.fs();
fs.mknod('/', 'DIRECTORY', function(error) {
expect(error.code).to.equal('EEXIST');
done();
});
});
it('should return an error if the parent node is not a directory', function(done) {
var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error, result) {
if(error) throw error;
fs.mknod('/file/myfile', 'FILE', function(error, result) {
expect(error.code).to.equal('ENOTDIR');
done();
});
});
});
it('should return an error if the mode provided is not DIRECTORY or FILE', function(done) {
var fs = util.fs();
fs.mknod('/symlink', 'SYMLINK', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
it('should make a new directory', function(done) {
var fs = util.fs();
fs.mknod('/dir', 'DIRECTORY', function(error) {
if(error) throw error;
fs.stat('/dir', function(error, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
});
it('should make a new file', function(done) {
var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error, result) {
if(error) throw error;
fs.stat('/file', function(error, result) {
expect(error).not.to.exist;
expect(result.type).to.equal('FILE');
done();
});
});
});
});

View File

@ -1,109 +1,109 @@
define(["Filer", "util", "src/constants"], function(Filer, util, constants) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
var constants = require('../../src/constants.js');
describe('fs.open', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.open', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.open).to.be.a('function');
it('should be a function', function() {
var fs = util.fs();
expect(fs.open).to.be.a('function');
});
it('should return an error if the parent path does not exist', function(done) {
var fs = util.fs();
fs.open('/tmp/myfile', 'w+', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
it('should return an error if the parent path does not exist', function(done) {
var fs = util.fs();
it('should return an error when flagged for read and the path does not exist', function(done) {
var fs = util.fs();
fs.open('/tmp/myfile', 'w+', function(error, result) {
fs.open('/myfile', 'r+', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
it('should return an error when flagged for write and the path is a directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp', 'w', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal("EISDIR");
expect(result).not.to.exist;
done();
});
});
it('should return an error when flagged for read and the path does not exist', function(done) {
var fs = util.fs();
fs.open('/myfile', 'r+', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
it('should return an error when flagged for write and the path is a directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp', 'w', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(result).not.to.exist;
done();
});
});
});
it('should return an error when flagged for append and the path is a directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp', 'a', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(result).not.to.exist;
done();
});
});
});
it('should return a unique file descriptor', function(done) {
var fs = util.fs();
var fd1;
fs.open('/file1', 'w+', function(error, fd) {
if(error) throw error;
expect(error).not.to.exist;
expect(fd).to.be.a('number');
fs.open('/file2', 'w+', function(error, fd) {
if(error) throw error;
expect(error).not.to.exist;
expect(fd).to.be.a('number');
expect(fd).not.to.equal(fd1);
done();
});
});
});
it('should return the argument value of the file descriptor index matching the value set by the first useable file descriptor constant', function(done) {
var fs = util.fs();
var firstFD = constants.FIRST_DESCRIPTOR;
var fd1;
fs.open('/file1', 'w+', function(error, fd) {
if(error) throw error;
expect(fd).to.equal(firstFD);
done();
});
});
it('should create a new file when flagged for write', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('FILE');
done();
});
});
});
});
it('should return an error when flagged for append and the path is a directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp', 'a', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(result).not.to.exist;
done();
});
});
});
it('should return a unique file descriptor', function(done) {
var fs = util.fs();
var fd1;
fs.open('/file1', 'w+', function(error, fd) {
if(error) throw error;
expect(error).not.to.exist;
expect(fd).to.be.a('number');
fs.open('/file2', 'w+', function(error, fd) {
if(error) throw error;
expect(error).not.to.exist;
expect(fd).to.be.a('number');
expect(fd).not.to.equal(fd1);
done();
});
});
});
it('should return the argument value of the file descriptor index matching the value set by the first useable file descriptor constant', function(done) {
var fs = util.fs();
var firstFD = constants.FIRST_DESCRIPTOR;
var fd1;
fs.open('/file1', 'w+', function(error, fd) {
if(error) throw error;
expect(fd).to.equal(firstFD);
done();
});
});
it('should create a new file when flagged for write', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('FILE');
done();
});
});
});
});

View File

@ -1,62 +1,62 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.read', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.read', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.read).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.read).to.be.a('function');
});
it('should read data from a file', function(done) {
var fs = util.fs();
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
it('should read data from a file', function(done) {
var fs = util.fs();
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
fs.open('/myfile', 'w+', function(error, fd) {
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
if(error) throw error;
fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(rbuffer.length);
expect(wbuffer).to.deep.equal(rbuffer);
done();
});
});
});
});
it('should update the current file position', function(done) {
var fs = util.fs();
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
var _result = 0;
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
if(error) throw error;
fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) {
if(error) throw error;
fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
_result += result;
fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
expect(error).not.to.exist;
expect(result).to.equal(rbuffer.length);
expect(_result).to.equal(rbuffer.length);
expect(wbuffer).to.deep.equal(rbuffer);
done();
});
});
});
});
it('should update the current file position', function(done) {
var fs = util.fs();
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
var _result = 0;
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
if(error) throw error;
fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) {
if(error) throw error;
_result += result;
fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
expect(error).not.to.exist;
expect(_result).to.equal(rbuffer.length);
expect(wbuffer).to.deep.equal(rbuffer);
done();
});
});
});
});
});
});
});
});

View File

@ -1,32 +1,51 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.readdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.readdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.readdir).to.be.a('function');
it('should be a function', function() {
var fs = util.fs();
expect(fs.readdir).to.be.a('function');
});
it('should return an error if the path does not exist', function(done) {
var fs = util.fs();
fs.readdir('/tmp/mydir', function(error, files) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(files).not.to.exist;
done();
});
});
it('should return an error if the path does not exist', function(done) {
var fs = util.fs();
it('should return a list of files from an existing directory', function(done) {
var fs = util.fs();
fs.readdir('/tmp/mydir', function(error, files) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(files).not.to.exist;
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.readdir('/', function(error, files) {
expect(error).not.to.exist;
expect(files).to.exist;
expect(files.length).to.equal(1);
expect(files[0]).to.equal('tmp');
done();
});
});
});
it('should return a list of files from an existing directory', function(done) {
var fs = util.fs();
it('should follow symbolic links', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.symlink('/', '/tmp/dirLink', function(error) {
if(error) throw error;
fs.readdir('/', function(error, files) {
fs.readdir('/tmp/dirLink', function(error, files) {
expect(error).not.to.exist;
expect(files).to.exist;
expect(files.length).to.equal(1);
@ -35,24 +54,5 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
it('should follow symbolic links', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.symlink('/', '/tmp/dirLink', function(error) {
if(error) throw error;
fs.readdir('/tmp/dirLink', function(error, files) {
expect(error).not.to.exist;
expect(files).to.exist;
expect(files.length).to.equal(1);
expect(files[0]).to.equal('tmp');
done();
});
});
});
});
});
});
});

View File

@ -1,47 +1,47 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.readlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.readlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.readlink).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.readlink).to.be.a('function');
});
it('should return an error if part of the parent destination path does not exist', function(done) {
var fs = util.fs();
it('should return an error if part of the parent destination path does not exist', function(done) {
var fs = util.fs();
fs.readlink('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return an error if the path is not a symbolic link', function(done) {
var fs = util.fs();
fs.readlink('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return the contents of a symbolic link', function(done) {
var fs = util.fs();
fs.symlink('/', '/myfile', function(error) {
if(error) throw error;
fs.readlink('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal('/');
done();
});
});
fs.readlink('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
});
it('should return an error if the path is not a symbolic link', function(done) {
var fs = util.fs();
fs.readlink('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return the contents of a symbolic link', function(done) {
var fs = util.fs();
fs.symlink('/', '/myfile', function(error) {
if(error) throw error;
fs.readlink('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal('/');
done();
});
});
});
});

View File

@ -1,50 +1,50 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.rename', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.rename', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.rename).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.rename).to.be.a('function');
});
it('should rename an existing file', function(done) {
var complete1 = false;
var complete2 = false;
var fs = util.fs();
it('should rename an existing file', function(done) {
var complete1 = false;
var complete2 = false;
var fs = util.fs();
function maybeDone() {
if(complete1 && complete2) {
done();
}
function maybeDone() {
if(complete1 && complete2) {
done();
}
}
fs.open('/myfile', 'w+', function(error, fd) {
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.close(fd, function(error) {
fs.rename('/myfile', '/myotherfile', function(error) {
if(error) throw error;
fs.rename('/myfile', '/myotherfile', function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
complete1 = true;
maybeDone();
});
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
complete1 = true;
maybeDone();
});
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(1);
complete2 = true;
maybeDone();
});
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(1);
complete2 = true;
maybeDone();
});
});
});
});
});
});

View File

@ -1,77 +1,62 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.rmdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.rmdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.rmdir).to.be.a('function');
it('should be a function', function() {
var fs = util.fs();
expect(fs.rmdir).to.be.a('function');
});
it('should return an error if the path does not exist', function(done) {
var fs = util.fs();
fs.rmdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return an error if the path does not exist', function(done) {
var fs = util.fs();
it('should return an error if attempting to remove the root directory', function(done) {
var fs = util.fs();
fs.rmdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
done();
});
});
it('should return an error if attempting to remove the root directory', function(done) {
var fs = util.fs();
it('should return an error if the directory is not empty', function(done) {
var fs = util.fs();
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
done();
});
});
it('should return an error if the directory is not empty', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.mkdir('/tmp/mydir', function(error) {
if(error) throw error;
fs.mkdir('/tmp/mydir', function(error) {
if(error) throw error;
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
done();
});
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
done();
});
});
});
});
it('should return an error if the path is not a directory', function(done) {
var fs = util.fs();
it('should return an error if the path is not a directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.open('/tmp/myfile', 'w', function(error, fd) {
fs.close(fd, function(error) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.rmdir('/tmp/myfile', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
done();
});
});
});
});
});
it('should return an error if the path is a symbolic link', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function (error) {
if(error) throw error;
fs.symlink('/tmp', '/tmp/myfile', function (error) {
if(error) throw error;
fs.rmdir('/tmp/myfile', function (error) {
fs.rmdir('/tmp/myfile', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
done();
@ -79,23 +64,38 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should remove an existing directory', function(done) {
var fs = util.fs();
it('should return an error if the path is a symbolic link', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
fs.mkdir('/tmp', function (error) {
if(error) throw error;
fs.symlink('/tmp', '/tmp/myfile', function (error) {
if(error) throw error;
fs.rmdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
fs.stat('/tmp', function(error, stats) {
expect(error).to.exist;
expect(stats).not.to.exist;
done();
});
fs.rmdir('/tmp/myfile', function (error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
done();
});
});
});
});
it('should remove an existing directory', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.rmdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
fs.stat('/tmp', function(error, stats) {
expect(error).to.exist;
expect(stats).not.to.exist;
done();
});
});
});
});
});

View File

@ -1,24 +1,24 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe("fs", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe("fs", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it("is an object", function() {
var fs = util.fs();
expect(typeof fs).to.equal('object');
expect(fs).to.be.an.instanceof(Filer.FileSystem);
});
it('should have a root directory', function(done) {
var fs = util.fs();
fs.stat('/', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
it("is an object", function() {
var fs = util.fs();
expect(typeof fs).to.equal('object');
expect(fs).to.be.an.instanceof(Filer.FileSystem);
});
it('should have a root directory', function(done) {
var fs = util.fs();
fs.stat('/', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
});

View File

@ -1,95 +1,95 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.stat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.stat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.stat).to.equal('function');
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.stat).to.equal('function');
});
it('should return an error if path does not exist', function(done) {
var fs = util.fs();
fs.stat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
it('should return an error if path does not exist', function(done) {
var fs = util.fs();
it('should return a stat object if path exists', function(done) {
var fs = util.fs();
fs.stat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
fs.stat('/', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exit;
expect(result['node']).to.be.a('string');
expect(result['dev']).to.equal(fs.name);
expect(result['size']).to.be.a('number');
expect(result['nlinks']).to.be.a('number');
expect(result['atime']).to.be.a('number');
expect(result['mtime']).to.be.a('number');
expect(result['ctime']).to.be.a('number');
expect(result['type']).to.equal('DIRECTORY');
done();
});
});
it('should follow symbolic links and return a stat object for the resulting path', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result['node']).to.exist;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.stat('/myfilelink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.exist;
done();
});
});
});
});
});
});
it('should return a stat object if path exists', function(done) {
var fs = util.fs();
it('should return a stat object for a valid descriptor', function(done) {
var fs = util.fs();
fs.stat('/', function(error, result) {
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exit;
expect(result).to.exist;
expect(result['node']).to.be.a('string');
expect(result['node']).to.exist;
expect(result['dev']).to.equal(fs.name);
expect(result['size']).to.be.a('number');
expect(result['nlinks']).to.be.a('number');
expect(result['atime']).to.be.a('number');
expect(result['mtime']).to.be.a('number');
expect(result['ctime']).to.be.a('number');
expect(result['type']).to.equal('DIRECTORY');
expect(result['type']).to.equal('FILE');
done();
});
});
it('should follow symbolic links and return a stat object for the resulting path', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result['node']).to.exist;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.stat('/myfilelink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.exist;
done();
});
});
});
});
});
});
it('should return a stat object for a valid descriptor', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.exist;
expect(result['dev']).to.equal(fs.name);
expect(result['size']).to.be.a('number');
expect(result['nlinks']).to.be.a('number');
expect(result['atime']).to.be.a('number');
expect(result['mtime']).to.be.a('number');
expect(result['ctime']).to.be.a('number');
expect(result['type']).to.equal('FILE');
done();
});
});
});
});
});
});

View File

@ -1,247 +1,248 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.stats', function() {
describe('#isFile()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.stats', function() {
describe('#isFile()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFile).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFile).to.be.a('function');
});
});
it('should return true if stats are for file', function(done) {
var fs = util.fs();
it('should return true if stats are for file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isFile()).to.be.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.be.false;
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isFile()).to.be.true;
done();
});
});
});
it('should return false if stats are for symbolic link', function(done) {
var fs = util.fs();
it('should return false if stats are for directory', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFile()).to.be.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.close(fd, function(error, stats) {
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.lstat('/myfilelink', function(error, stats) {
expect(stats.isFile()).to.be.false;
done();
});
fs.lstat('/myfilelink', function(error, stats) {
expect(stats.isFile()).to.be.false;
done();
});
});
});
});
});
describe('#isDirectory()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isDirectory).to.be.a('function');
});
});
it('should return false if stats are for file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isDirectory()).to.be.false;
done();
});
});
});
it('should return true if stats are for directory', function(done) {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isDirectory()).to.be.true;
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.isDirectory()).to.be.false;
done();
});
});
});
});
});
});
describe('#isBlockDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isBlockDevice).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isBlockDevice()).to.be.false;
});
});
});
describe('#isCharacterDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isCharacterDevice).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isCharacterDevice()).to.be.false;
});
});
});
describe('#isSymbolicLink()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSymbolicLink).to.be.a('function');
});
});
it('should return false if stats are for file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isSymbolicLink()).to.be.false;
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.isSymbolicLink()).to.be.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.be.true;
done();
});
});
});
});
});
});
describe('#isFIFO()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFIFO).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFIFO()).to.be.false;
});
});
});
describe('#isSocket()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSocket).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSocket()).to.be.false;
});
});
});
});
});
describe('#isDirectory()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isDirectory).to.be.a('function');
});
});
it('should return false if stats are for file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isDirectory()).to.be.false;
done();
});
});
});
it('should return true if stats are for directory', function(done) {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isDirectory()).to.be.true;
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.isDirectory()).to.be.false;
done();
});
});
});
});
});
});
describe('#isBlockDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isBlockDevice).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isBlockDevice()).to.be.false;
});
});
});
describe('#isCharacterDevice()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isCharacterDevice).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isCharacterDevice()).to.be.false;
});
});
});
describe('#isSymbolicLink()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSymbolicLink).to.be.a('function');
});
});
it('should return false if stats are for file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.fstat(fd, function(error, stats) {
expect(stats.isSymbolicLink()).to.be.false;
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.isSymbolicLink()).to.be.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.be.true;
done();
});
});
});
});
});
});
describe('#isFIFO()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFIFO).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isFIFO()).to.be.false;
});
});
});
describe('#isSocket()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSocket).to.be.a('function');
});
});
it('should return false', function() {
var fs = util.fs();
fs.stat('/', function(error, stats) {
if(error) throw error;
expect(stats.isSocket()).to.be.false;
});
});
});
});

View File

@ -1,47 +1,47 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.symlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.symlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.symlink).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.symlink).to.be.a('function');
});
it('should return an error if part of the parent destination path does not exist', function(done) {
var fs = util.fs();
it('should return an error if part of the parent destination path does not exist', function(done) {
var fs = util.fs();
fs.symlink('/', '/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return an error if the destination path already exists', function(done) {
var fs = util.fs();
fs.symlink('/tmp', '/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
done();
});
});
it('should create a symlink', function(done) {
var fs = util.fs();
fs.symlink('/', '/myfile', function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(err, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
fs.symlink('/', '/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
done();
});
});
it('should return an error if the destination path already exists', function(done) {
var fs = util.fs();
fs.symlink('/tmp', '/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
done();
});
});
it('should create a symlink', function(done) {
var fs = util.fs();
fs.symlink('/', '/myfile', function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(err, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
});
});

View File

@ -1,143 +1,119 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.truncate', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.truncate', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.truncate).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.truncate).to.be.a('function');
});
it('should error when length is negative', function(done) {
var fs = util.fs();
var contents = "This is a file.";
it('should error when length is negative', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
fs.truncate('/myfile', -1, function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
done();
});
});
});
it('should error when path is not a file', function(done) {
var fs = util.fs();
fs.truncate('/', 0, function(error) {
fs.truncate('/myfile', -1, function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(error.code).to.equal("EINVAL");
done();
});
});
});
it('should truncate a file', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Uint8Array([1]);
it('should error when path is not a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', 1, function(error) {
expect(error).not.to.exist;
fs.readFile('/myfile', function(error, result) {
if(error) throw error;
expect(result).to.deep.equal(truncated);
done();
});
});
});
});
});
fs.truncate('/', 0, function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
done();
});
});
it('should pad a file with zeros when the length is greater than the file size', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0]);
it('should truncate a file', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Uint8Array([1]);
fs.open('/myfile', 'w', function(error, result) {
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
fs.close(fd, function(error) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', 9, function(error) {
expect(error).not.to.exist;
fs.readFile('/myfile', function(error, result) {
if(error) throw error;
expect(result).to.deep.equal(truncated);
done();
});
});
});
});
});
});
it('should update the file size', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', 0, function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(0);
done();
});
});
});
});
});
});
it('should truncate a valid descriptor', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.ftruncate(fd, 0, function(error) {
fs.truncate('/myfile', 1, function(error) {
expect(error).not.to.exist;
fs.fstat(fd, function(error, result) {
fs.readFile('/myfile', function(error, result) {
if(error) throw error;
expect(result).to.deep.equal(truncated);
done();
});
});
});
});
});
});
it('should pad a file with zeros when the length is greater than the file size', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', 9, function(error) {
expect(error).not.to.exist;
fs.readFile('/myfile', function(error, result) {
if(error) throw error;
expect(result).to.deep.equal(truncated);
done();
});
});
});
});
});
});
it('should update the file size', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', 0, function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(0);
@ -147,37 +123,62 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should follow symbolic links', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
it('should truncate a valid descriptor', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.ftruncate(fd, 0, function(error) {
expect(error).not.to.exist;
fs.close(fd, function(error) {
fs.fstat(fd, function(error, result) {
if(error) throw error;
fs.symlink('/myfile', '/mylink', function(error) {
if(error) throw error;
expect(result.size).to.equal(0);
done();
});
});
});
});
});
fs.truncate('/mylink', 0, function(error) {
expect(error).not.to.exist;
it('should follow symbolic links', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.stat('/myfile', function(error, result) {
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/mylink', function(error) {
if(error) throw error;
fs.truncate('/mylink', 0, function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(0);
fs.lstat('/mylink', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(0);
fs.lstat('/mylink', function(error, result) {
if(error) throw error;
expect(result.size).not.to.equal(0);
done();
});
expect(result.size).not.to.equal(0);
done();
});
});
});
@ -186,4 +187,4 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
});

View File

@ -1,80 +1,50 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.unlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.unlink', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.unlink).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.unlink).to.be.a('function');
});
it('should remove a link to an existing file', function(done) {
var fs = util.fs();
var complete1, complete2;
it('should remove a link to an existing file', function(done) {
var fs = util.fs();
var complete1, complete2;
function maybeDone() {
if(complete1 && complete2) {
done();
}
function maybeDone() {
if(complete1 && complete2) {
done();
}
}
fs.open('/myfile', 'w+', function(error, fd) {
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.close(fd, function(error) {
fs.link('/myfile', '/myotherfile', function(error) {
if(error) throw error;
fs.link('/myfile', '/myotherfile', function(error) {
fs.unlink('/myfile', function(error) {
if(error) throw error;
fs.unlink('/myfile', function(error) {
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
complete1 = true;
maybeDone();
});
fs.stat('/myotherfile', function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
complete1 = true;
maybeDone();
});
fs.stat('/myotherfile', function(error, result) {
if(error) throw error;
expect(result.nlinks).to.equal(1);
complete2 = true;
maybeDone();
});
});
});
});
});
});
it('should not follow symbolic links', function(done) {
var fs = util.fs();
fs.symlink('/', '/myFileLink', function (error) {
if (error) throw error;
fs.link('/myFileLink', '/myotherfile', function (error) {
if (error) throw error;
fs.unlink('/myFileLink', function (error) {
if (error) throw error;
fs.lstat('/myFileLink', function (error, result) {
expect(error).to.exist;
fs.lstat('/myotherfile', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
fs.stat('/', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
done();
});
});
expect(result.nlinks).to.equal(1);
complete2 = true;
maybeDone();
});
});
});
@ -82,4 +52,34 @@ define(["Filer", "util"], function(Filer, util) {
});
});
it('should not follow symbolic links', function(done) {
var fs = util.fs();
fs.symlink('/', '/myFileLink', function (error) {
if (error) throw error;
fs.link('/myFileLink', '/myotherfile', function (error) {
if (error) throw error;
fs.unlink('/myFileLink', function (error) {
if (error) throw error;
fs.lstat('/myFileLink', function (error, result) {
expect(error).to.exist;
fs.lstat('/myotherfile', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
fs.stat('/', function (error, result) {
if (error) throw error;
expect(result.nlinks).to.equal(1);
done();
});
});
});
});
});
});
});
});

View File

@ -1,177 +1,178 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.utimes', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.utimes', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.utimes).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.utimes).to.be.a('function');
});
it('should error when atime is negative', function(done) {
var fs = util.fs();
it('should error when atime is negative', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.utimes('/testfile', -1, Date.now(), function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when mtime is negative', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.utimes('/testfile', Date.now(), -1, function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when atime is as invalid number', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when path does not exist', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.utimes('/pathdoesnotexist', atime, mtime, function (error) {
fs.utimes('/testfile', -1, Date.now(), function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when mtime is an invalid number', function(done) {
var fs = util.fs();
it('should error when mtime is negative', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
fs.utimes('/testfile', Date.now(), -1, function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when atime is as invalid number', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when path does not exist', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.utimes('/pathdoesnotexist', atime, mtime, function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
done();
});
});
it('should error when mtime is an invalid number', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when file descriptor is invalid', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.futimes(1, atime, mtime, function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
done();
});
});
it('should change atime and mtime of a file path', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.utimes('/testfile', atime, mtime, function (error) {
expect(error).not.to.exist;
fs.stat('/testfile', function (error, stat) {
expect(error).not.to.exist;
expect(stat.mtime).to.equal(mtime);
done();
});
});
});
});
it('should error when file descriptor is invalid', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
it ('should change atime and mtime for a valid file descriptor', function(done) {
var fs = util.fs();
var ofd;
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.futimes(1, atime, mtime, function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
done();
});
});
fs.open('/testfile', 'w', function (error, result) {
if (error) throw error;
it('should change atime and mtime of a file path', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
ofd = result;
fs.futimes(ofd, atime, mtime, function (error) {
expect(error).not.to.exist;
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.utimes('/testfile', atime, mtime, function (error) {
fs.fstat(ofd, function (error, stat) {
expect(error).not.to.exist;
fs.stat('/testfile', function (error, stat) {
expect(error).not.to.exist;
expect(stat.mtime).to.equal(mtime);
expect(stat.mtime).to.equal(mtime);
done();
});
});
});
});
});
it ('should change atime and mtime for a valid file descriptor', function(done) {
var fs = util.fs();
var ofd;
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
it('should update atime and mtime of directory path', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.open('/testfile', 'w', function (error, result) {
if (error) throw error;
fs.mkdir('/testdir', function (error) {
if (error) throw error;
ofd = result;
fs.futimes(ofd, atime, mtime, function (error) {
fs.utimes('/testdir', atime, mtime, function (error) {
expect(error).not.to.exist;
fs.stat('/testdir', function (error, stat) {
expect(error).not.to.exist;
fs.fstat(ofd, function (error, stat) {
expect(error).not.to.exist;
expect(stat.mtime).to.equal(mtime);
done();
});
expect(stat.mtime).to.equal(mtime);
done();
});
});
});
});
it('should update atime and mtime of directory path', function(done) {
var fs = util.fs();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
it('should update atime and mtime using current time if arguments are null', function(done) {
var fs = util.fs();
var atimeEst;
var mtimeEst;
fs.mkdir('/testdir', function (error) {
if (error) throw error;
fs.writeFile('/myfile', '', function (error) {
if (error) throw error;
fs.utimes('/testdir', atime, mtime, function (error) {
var then = Date.now();
fs.utimes('/myfile', null, null, function (error) {
expect(error).not.to.exist;
fs.stat('/myfile', function (error, stat) {
expect(error).not.to.exist;
fs.stat('/testdir', function (error, stat) {
expect(error).not.to.exist;
expect(stat.mtime).to.equal(mtime);
done();
});
});
});
});
it('should update atime and mtime using current time if arguments are null', function(done) {
var fs = util.fs();
var atimeEst;
var mtimeEst;
fs.writeFile('/myfile', '', function (error) {
if (error) throw error;
var then = Date.now();
fs.utimes('/myfile', null, null, function (error) {
expect(error).not.to.exist;
fs.stat('/myfile', function (error, stat) {
expect(error).not.to.exist;
// Note: testing estimation as time may differ by a couple of milliseconds
// This number should be increased if tests are on slow systems
var delta = Date.now() - then;
expect(then - stat.atime).to.be.at.most(delta);
expect(then - stat.mtime).to.be.at.most(delta);
done();
});
// Note: testing estimation as time may differ by a couple of milliseconds
// This number should be increased if tests are on slow systems
var delta = Date.now() - then;
expect(then - stat.atime).to.be.at.most(delta);
expect(then - stat.mtime).to.be.at.most(delta);
done();
});
});
});

View File

@ -1,43 +1,43 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.watch', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.watch', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.watch).to.equal('function');
it('should be a function', function() {
var fs = util.fs();
expect(typeof fs.watch).to.equal('function');
});
it('should get a change event when writing a file', function(done) {
var fs = util.fs();
var watcher = fs.watch('/myfile', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/myfile');
watcher.close();
done();
});
it('should get a change event when writing a file', function(done) {
var fs = util.fs();
var watcher = fs.watch('/myfile', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/myfile');
watcher.close();
done();
});
fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;
});
});
it('should get a change event when writing a file in a dir with recursive=true', function(done) {
var fs = util.fs();
var watcher = fs.watch('/', { recursive: true }, function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/');
watcher.close();
done();
});
fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;
});
fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;
});
});
it('should get a change event when writing a file in a dir with recursive=true', function(done) {
var fs = util.fs();
var watcher = fs.watch('/', { recursive: true }, function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/');
watcher.close();
done();
});
fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;
});
});
});

View File

@ -1,62 +1,62 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.write', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.write', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.write).to.be.a('function');
});
it('should be a function', function() {
var fs = util.fs();
expect(fs.write).to.be.a('function');
});
it('should write data to a file', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
it('should write data to a file', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(buffer.length);
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal(buffer.length);
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result.type).to.equal('FILE');
expect(result.size).to.equal(buffer.length);
done();
});
});
});
});
it('should update the current file position', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var _result = 0;
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(error).not.to.exist;
expect(_result).to.equal(2 * buffer.length);
expect(result.size).to.equal(_result);
done();
});
});
expect(result.type).to.equal('FILE');
expect(result.size).to.equal(buffer.length);
done();
});
});
});
});
it('should update the current file position', function(done) {
var fs = util.fs();
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var _result = 0;
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(error).not.to.exist;
expect(_result).to.equal(2 * buffer.length);
expect(result.size).to.equal(_result);
done();
});
});
});
});
});
});

View File

@ -1,104 +1,104 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.writeFile, fs.readFile', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.writeFile, fs.readFile', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.writeFile).to.be.a('function');
expect(fs.readFile).to.be.a('function');
it('should be a function', function() {
var fs = util.fs();
expect(fs.writeFile).to.be.a('function');
expect(fs.readFile).to.be.a('function');
});
it('should error when path is wrong to readFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.readFile('/no-such-file', 'utf8', function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(data).not.to.exist;
done();
});
});
it('should error when path is wrong to readFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.readFile('/no-such-file', 'utf8', function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(data).not.to.exist;
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
});
});
it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
it('should write, read a utf8 file with "utf8" option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
fs.writeFile('/myfile', contents, 'utf8', function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
});
});
it('should write, read a utf8 file with "utf8" option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.writeFile('/myfile', contents, 'utf8', function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
});
});
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
it('should write, read a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var binary = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.readFile('/myfile', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
fs.writeFile('/myfile', binary, function(error) {
if(error) throw error;
fs.readFile('/myfile', function(error, data) {
expect(error).not.to.exist;
expect(data).to.deep.equal(binary);
done();
});
});
});
it('should write, read a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var binary = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.writeFile('/myfile', binary, function(error) {
if(error) throw error;
fs.readFile('/myfile', function(error, data) {
expect(error).not.to.exist;
expect(data).to.deep.equal(binary);
done();
});
});
});
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myFileLink', function (error) {
fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
fs.writeFile('/myFileLink', contents, 'utf8', function (error) {
if (error) throw error;
fs.writeFile('/myFileLink', contents, 'utf8', function (error) {
if (error) throw error;
fs.readFile('/myFileLink', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
fs.readFile('/myFileLink', 'utf8', function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents);
done();
});
});
});
});
});
});
});

View File

@ -1,393 +1,394 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.xattr', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('fs.xattr', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function () {
var fs = util.fs();
expect(fs.setxattr).to.be.a('function');
expect(fs.getxattr).to.be.a('function');
expect(fs.removexattr).to.be.a('function');
expect(fs.fsetxattr).to.be.a('function');
expect(fs.fgetxattr).to.be.a('function');
it('should be a function', function () {
var fs = util.fs();
expect(fs.setxattr).to.be.a('function');
expect(fs.getxattr).to.be.a('function');
expect(fs.removexattr).to.be.a('function');
expect(fs.fsetxattr).to.be.a('function');
expect(fs.fgetxattr).to.be.a('function');
});
it('should error when setting with a name that is not a string', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 89, 'testvalue', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when setting with a name that is not a string', function(done) {
var fs = util.fs();
it('should error when setting with a name that is null', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', null, 'testvalue', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when setting with an invalid flag', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 89, 'testvalue', function (error) {
fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
expect(error.code).to.equal('EEXIST');
done();
});
});
});
});
it('should error when setting with a name that is null', function(done) {
var fs = util.fs();
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.setxattr('/testfile', null, 'testvalue', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
it('should error when setting with an invalid flag', function(done) {
var fs = util.fs();
it('should error when getting an attribute with a name that is empty', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
fs.getxattr('/testfile', '', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) {
var fs = util.fs();
it('should error when getting an attribute where the name is not a string', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EEXIST');
done();
});
});
fs.getxattr('/testfile', 89, function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) {
var fs = util.fs();
it('should error when getting an attribute that does not exist', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
fs.getxattr('/testfile', 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
it('should error when getting an attribute with a name that is empty', function(done) {
var fs = util.fs();
it('should error when file descriptor is invalid', function(done) {
var fs = util.fs();
var completeSet, completeGet, completeRemove;
var _value;
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
completeSet = completeGet = completeRemove = false;
fs.getxattr('/testfile', '', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when getting an attribute where the name is not a string', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.getxattr('/testfile', 89, function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
});
it('should error when getting an attribute that does not exist', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function(error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
it('should error when file descriptor is invalid', function(done) {
var fs = util.fs();
var completeSet, completeGet, completeRemove;
var _value;
completeSet = completeGet = completeRemove = false;
function maybeDone() {
if(completeSet && completeGet && completeRemove) {
done();
}
function maybeDone() {
if(completeSet && completeGet && completeRemove) {
done();
}
}
fs.fsetxattr(1, 'test', 'value', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
completeSet = true;
maybeDone();
});
fs.fgetxattr(1, 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
expect(value).not.to.exist;
completeGet = true;
maybeDone();
});
fs.fremovexattr(1, 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
completeRemove = true;
maybeDone();
});
fs.fsetxattr(1, 'test', 'value', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
completeSet = true;
maybeDone();
});
it('should set and get an extended attribute of a path', function(done) {
var fs = util.fs();
var name = 'test';
fs.fgetxattr(1, 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
expect(value).not.to.exist;
completeGet = true;
maybeDone();
});
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.fremovexattr(1, 'test', function(error, value) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
completeRemove = true;
maybeDone();
});
});
fs.setxattr('/testfile', name, 'somevalue', function(error) {
it('should set and get an extended attribute of a path', function(done) {
var fs = util.fs();
var name = 'test';
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', name, 'somevalue', function(error) {
expect(error).not.to.exist;
fs.getxattr('/testfile', name, function(error, value) {
expect(error).not.to.exist;
fs.getxattr('/testfile', name, function(error, value) {
expect(error).not.to.exist;
expect(value).to.equal('somevalue');
done();
});
expect(value).to.equal('somevalue');
done();
});
});
});
});
it('should error when attempting to remove a non-existing attribute', function(done) {
var fs = util.fs();
it('should error when attempting to remove a non-existing attribute', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', '', function (error) {
if (error) throw error;
fs.removexattr('/testfile', 'testenoattr', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
fs.removexattr('/testfile', 'testenoattr', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
});
it('should set and get an empty string as a value', function(done) {
var fs = util.fs();
it('should set and get an empty string as a value', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', '', function (error) {
if(error) throw error;
fs.setxattr('/testfile', 'test', '', function (error) {
if(error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.equal('');
done();
});
});
});
});
it('should set and get an extended attribute for a valid file descriptor', function(done) {
var fs = util.fs();
fs.open('/testfile', 'w', function (error, ofd) {
if (error) throw error;
fs.fsetxattr(ofd, 'test', 'value', function (error) {
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
fs.fgetxattr(ofd, 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.equal('value');
done();
});
expect(value).to.equal('');
done();
});
});
});
});
it('should set and get an object to an extended attribute', function(done) {
var fs = util.fs();
it('should set and get an extended attribute for a valid file descriptor', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.open('/testfile', 'w', function (error, ofd) {
if (error) throw error;
fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) {
if(error) throw error;
fs.fsetxattr(ofd, 'test', 'value', function (error) {
expect(error).not.to.exist;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 });
done();
});
fs.fgetxattr(ofd, 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.equal('value');
done();
});
});
});
});
it('should update/overwrite an existing extended attribute', function(done) {
var fs = util.fs();
it('should set and get an object to an extended attribute', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) {
if(error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 });
done();
});
});
});
});
it('should update/overwrite an existing extended attribute', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'value', function (error) {
fs.getxattr('/testfile', 'test', function (error, value) {
if (error) throw error;
expect(value).to.equal('value');
fs.getxattr('/testfile', 'test', function (error, value) {
fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) {
if (error) throw error;
expect(value).to.equal('value');
fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) {
fs.getxattr('/testfile', 'test', function (error, value) {
if (error) throw error;
expect(value).to.deep.equal({ o: 'object', t: 'test' });
fs.getxattr('/testfile', 'test', function (error, value) {
fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) {
if (error) throw error;
expect(value).to.deep.equal({ o: 'object', t: 'test' });
fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(value).to.equal(100);
done();
});
fs.getxattr('/testfile', 'test', function (error, value) {
expect(value).to.equal(100);
done();
});
});
});
});
})
});
});
})
});
});
it('should set multiple extended attributes for a path', function(done) {
var fs = util.fs();
it('should set multiple extended attributes for a path', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 89, function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 89, function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'other', 'attribute', function (error) {
if(error) throw error;
fs.setxattr('/testfile', 'other', 'attribute', function (error) {
fs.getxattr('/testfile', 'test', function (error, value) {
if(error) throw error;
expect(value).to.equal(89);
fs.getxattr('/testfile', 'test', function (error, value) {
if(error) throw error;
expect(value).to.equal(89);
fs.getxattr('/testfile', 'other', function (error, value) {
expect(error).not.to.exist;
expect(value).to.equal('attribute');
done();
});
fs.getxattr('/testfile', 'other', function (error, value) {
expect(error).not.to.exist;
expect(value).to.equal('attribute');
done();
});
});
});
});
});
it('should remove an extended attribute from a path', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'somevalue', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
if (error) throw error;
expect(value).to.equal('somevalue');
fs.removexattr('/testfile', 'test', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
});
});
});
it('should remove an extended attribute from a valid file descriptor', function(done) {
var fs = util.fs();
fs.open('/testfile', 'w', function (error, ofd) {
if (error) throw error;
fs.fsetxattr(ofd, 'test', 'somevalue', function (error) {
if (error) throw error;
fs.fgetxattr(ofd, 'test', function (error, value) {
if (error) throw error;
expect(value).to.equal('somevalue');
fs.fremovexattr(ofd, 'test', function (error) {
if (error) throw error;
fs.fgetxattr(ofd, 'test', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
});
});
});
it('should allow setting with a null value', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', null, function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.be.null;
done();
});
});
});
});
});
it('should remove an extended attribute from a path', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', 'somevalue', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
if (error) throw error;
expect(value).to.equal('somevalue');
fs.removexattr('/testfile', 'test', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
});
});
});
it('should remove an extended attribute from a valid file descriptor', function(done) {
var fs = util.fs();
fs.open('/testfile', 'w', function (error, ofd) {
if (error) throw error;
fs.fsetxattr(ofd, 'test', 'somevalue', function (error) {
if (error) throw error;
fs.fgetxattr(ofd, 'test', function (error, value) {
if (error) throw error;
expect(value).to.equal('somevalue');
fs.fremovexattr(ofd, 'test', function (error) {
if (error) throw error;
fs.fgetxattr(ofd, 'test', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOATTR');
done();
});
});
});
});
});
});
it('should allow setting with a null value', function(done) {
var fs = util.fs();
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.setxattr('/testfile', 'test', null, function (error) {
if (error) throw error;
fs.getxattr('/testfile', 'test', function (error, value) {
expect(error).not.to.exist;
expect(value).to.be.null;
done();
});
});
});
});
});

View File

@ -1,66 +1,66 @@
define(['../../src/network'], function(network) {
var network = require('../../src/network.js');
var expect = require('chai').expect;
describe('Network download tool', function() {
var uri;
describe('Network download tool', function() {
var uri;
if (typeof XMLHttpRequest === 'undefined') {
// Node context
uri = {
valid: 'http://localhost:1234/package.json',
invalid: 'booyah!',
notFound: 'http://localhost:1234/this-isnt-real'
}
} else {
// Browser context
uri = {
valid: '../package.json',
invalid: 'asdf://booyah!',
notFound: 'this-isnt-real'
};
if (typeof XMLHttpRequest === 'undefined') {
// Node context
uri = {
valid: 'http://localhost:1234/package.json',
invalid: 'booyah!',
notFound: 'http://localhost:1234/this-isnt-real'
}
} else {
// Browser context
uri = {
valid: '../package.json',
invalid: 'asdf://booyah!',
notFound: 'this-isnt-real'
};
}
it('should throw an exception when a URI is not passed', function(done) {
expect(function() {
network.download(undefined, function(error, data) {});
}).to.throwError;
it('should throw an exception when a URI is not passed', function(done) {
expect(function() {
network.download(undefined, function(error, data) {});
}).to.throwError;
done();
});
it('should get an error when a non-existent path is specified', function(done) {
network.download(uri.notFound, function(error, data) {
expect(error).to.exist;
expect(error.code).to.eql(404);
expect(data).to.be.eql(null);
done();
});
});
it('should get an error when a non-existent path is specified', function(done) {
network.download(uri.notFound, function(error, data) {
if (typeof XMLHttpRequest === 'undefined') {
it('in nodejs, should get an error when an invalid URI is specified', function(done) {
network.download(uri.invalid, function(error, data) {
expect(error).to.exist;
expect(error.code).to.eql(404);
expect(error.code).to.eql(null);
expect(error.message).to.exist;
expect(data).to.be.eql(null);
done();
});
});
} else {
it('in a browser, should throw an error when an invalid URI is specified', function(done) {
expect(function(){
network.download(uri.invalid, function() {});
}).to.throwError;
done();
});
}
if (typeof XMLHttpRequest === 'undefined') {
it('in nodejs, should get an error when an invalid URI is specified', function(done) {
network.download(uri.invalid, function(error, data) {
expect(error).to.exist;
expect(error.code).to.eql(null);
expect(error.message).to.exist;
expect(data).to.be.eql(null);
done();
});
});
} else {
it('in a browser, should throw an error when an invalid URI is specified', function(done) {
expect(function(){
network.download(uri.invalid, function() {});
}).to.throwError;
done();
});
}
it('should download a resource from the server', function(done) {
network.download(uri.valid, function(error, data) {
expect(error).not.to.exist;
expect(data).to.exist;
expect(data).to.have.length.above(0);
done();
});
it('should download a resource from the server', function(done) {
network.download(uri.valid, function(error, data) {
expect(error).not.to.exist;
expect(data).to.exist;
expect(data).to.have.length.above(0);
done();
});
});
});

View File

@ -1,41 +1,40 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../../..');
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() {
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
beforeEach(util.setup);
afterEach(util.cleanup);
// Based on test1 from https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir without a mode arg', function(done) {
var pathname = '/test1';
var fs = util.fs();
// Based on test1 from https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir without a mode arg', function(done) {
var pathname = '/test1';
var fs = util.fs();
fs.mkdir(pathname, function(error) {
if(error) throw error;
fs.stat(pathname, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
});
// Based on test2 https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir with a mode arg', function(done) {
var pathname = '/test2';
var fs = util.fs();
fs.mkdir(pathname, 511 /*=0777*/, function(error) {
if(error) throw error;
fs.stat(pathname, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
fs.mkdir(pathname, function(error) {
if(error) throw error;
fs.stat(pathname, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
});
// Based on test2 https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir with a mode arg', function(done) {
var pathname = '/test2';
var fs = util.fs();
fs.mkdir(pathname, 511 /*=0777*/, function(error) {
if(error) throw error;
fs.stat(pathname, function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('DIRECTORY');
done();
});
});
});
});

View File

@ -1,62 +1,62 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../../..');
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() {
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
beforeEach(util.setup);
afterEach(util.cleanup);
it('should reject paths with null bytes in them', function(done) {
var checks = [];
var fnCount = 0;
var fnTotal = 16;
var expected = "Path must be a string without null bytes.";
var fs = util.fs();
it('should reject paths with null bytes in them', function(done) {
var checks = [];
var fnCount = 0;
var fnTotal = 16;
var expected = "Path must be a string without null bytes.";
var fs = util.fs();
// Make sure function fails with null path error in callback.
function check(fn) {
var args = Array.prototype.slice.call(arguments, 1);
args = args.concat(function(err) {
checks.push(function(){
expect(err).to.exist;
expect(err.message).to.equal(expected);
});
fnCount++;
if(fnCount === fnTotal) {
done();
}
// Make sure function fails with null path error in callback.
function check(fn) {
var args = Array.prototype.slice.call(arguments, 1);
args = args.concat(function(err) {
checks.push(function(){
expect(err).to.exist;
expect(err.message).to.equal(expected);
});
fn.apply(fs, args);
}
check(fs.link, '/foo\u0000bar', 'foobar');
check(fs.link, '/foobar', 'foo\u0000bar');
check(fs.lstat, '/foo\u0000bar');
check(fs.mkdir, '/foo\u0000bar', '0755');
check(fs.open, '/foo\u0000bar', 'r');
check(fs.readFile, '/foo\u0000bar');
check(fs.readdir, '/foo\u0000bar');
check(fs.readlink, '/foo\u0000bar');
check(fs.rename, '/foo\u0000bar', 'foobar');
check(fs.rename, '/foobar', 'foo\u0000bar');
check(fs.rmdir, '/foo\u0000bar');
check(fs.stat, '/foo\u0000bar');
check(fs.symlink, '/foo\u0000bar', 'foobar');
check(fs.symlink, '/foobar', 'foo\u0000bar');
check(fs.unlink, '/foo\u0000bar');
check(fs.writeFile, '/foo\u0000bar');
check(fs.appendFile, '/foo\u0000bar');
check(fs.truncate, '/foo\u0000bar');
check(fs.utimes, '/foo\u0000bar', 0, 0);
// TODO - need to be implemented still...
// check(fs.realpath, '/foo\u0000bar');
// check(fs.chmod, '/foo\u0000bar', '0644');
// check(fs.chown, '/foo\u0000bar', 12, 34);
// check(fs.realpath, '/foo\u0000bar');
checks.forEach(function(fn){
fn();
fnCount++;
if(fnCount === fnTotal) {
done();
}
});
fn.apply(fs, args);
}
check(fs.link, '/foo\u0000bar', 'foobar');
check(fs.link, '/foobar', 'foo\u0000bar');
check(fs.lstat, '/foo\u0000bar');
check(fs.mkdir, '/foo\u0000bar', '0755');
check(fs.open, '/foo\u0000bar', 'r');
check(fs.readFile, '/foo\u0000bar');
check(fs.readdir, '/foo\u0000bar');
check(fs.readlink, '/foo\u0000bar');
check(fs.rename, '/foo\u0000bar', 'foobar');
check(fs.rename, '/foobar', 'foo\u0000bar');
check(fs.rmdir, '/foo\u0000bar');
check(fs.stat, '/foo\u0000bar');
check(fs.symlink, '/foo\u0000bar', 'foobar');
check(fs.symlink, '/foobar', 'foo\u0000bar');
check(fs.unlink, '/foo\u0000bar');
check(fs.writeFile, '/foo\u0000bar');
check(fs.appendFile, '/foo\u0000bar');
check(fs.truncate, '/foo\u0000bar');
check(fs.utimes, '/foo\u0000bar', 0, 0);
// TODO - need to be implemented still...
// check(fs.realpath, '/foo\u0000bar');
// check(fs.chmod, '/foo\u0000bar', '0644');
// check(fs.chown, '/foo\u0000bar', 12, 34);
// check(fs.realpath, '/foo\u0000bar');
checks.forEach(function(fn){
fn();
});
});
});

View File

@ -1,38 +1,36 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../../..');
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
/**
* NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of
* fd vs. path) for events, or gives only a portion thereof (e.g., basname),
* we give full, abs paths always.
*/
/**
* NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of
* fd vs. path) for events, or gives only a portion thereof (e.g., basname),
* we give full, abs paths always.
*/
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js", function() {
it('should get change event for writeFile() under a recursive watched dir', function(done) {
var fs = util.fs();
beforeEach(util.setup);
afterEach(util.cleanup);
fs.mkdir('/test', function(error) {
if(error) throw error;
it('should get change event for writeFile() under a recursive watched dir', function(done) {
var fs = util.fs();
fs.mkdir('/test', function(error) {
fs.mkdir('/test/subdir', function(error) {
if(error) throw error;
fs.mkdir('/test/subdir', function(error) {
if(error) throw error;
var watcher = fs.watch('/test', {recursive: true});
watcher.on('change', function(event, filename) {
expect(event).to.equal('change');
// Expect to see that a new file was created in /test/subdir
expect(filename).to.equal('/test/subdir');
watcher.close();
done();
});
fs.writeFile('/test/subdir/watch.txt', 'world');
var watcher = fs.watch('/test', {recursive: true});
watcher.on('change', function(event, filename) {
expect(event).to.equal('change');
// Expect to see that a new file was created in /test/subdir
expect(filename).to.equal('/test/subdir');
watcher.close();
done();
});
fs.writeFile('/test/subdir/watch.txt', 'world');
});
});
});
});

View File

@ -1,73 +1,72 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../../..');
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
/**
* NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of
* fd vs. path) for events, or gives only a portion thereof (e.g., basname),
* we give full, abs paths always.
*/
/**
* NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of
* fd vs. path) for events, or gives only a portion thereof (e.g., basname),
* we give full, abs paths always.
*/
var filenameOne = '/watch.txt';
var filenameTwo = '/hasOwnProperty';
var filenameOne = '/watch.txt';
var filenameTwo = '/hasOwnProperty';
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js", function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js", function() {
it('should get change event for writeFile() using FSWatcher object', function(done) {
var fs = util.fs();
var changes = 0;
beforeEach(util.setup);
afterEach(util.cleanup);
var watcher = fs.watch(filenameOne);
watcher.on('change', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal(filenameOne);
it('should get change event for writeFile() using FSWatcher object', function(done) {
var fs = util.fs();
var changes = 0;
// Make sure only one change event comes in (i.e., close() works)
changes++;
watcher.close();
var watcher = fs.watch(filenameOne);
watcher.on('change', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal(filenameOne);
// Make sure only one change event comes in (i.e., close() works)
changes++;
watcher.close();
fs.writeFile(filenameOne, 'hello again', function(error) {
expect(changes).to.equal(1);
done();
});
fs.writeFile(filenameOne, 'hello again', function(error) {
expect(changes).to.equal(1);
done();
});
fs.writeFile(filenameOne, 'hello');
});
it('should get change event for writeFile() using fs.watch() only', function(done) {
var fs = util.fs();
var changes = 0;
fs.writeFile(filenameOne, 'hello');
});
var watcher = fs.watch(filenameTwo, function(event, filename) {
it('should get change event for writeFile() using fs.watch() only', function(done) {
var fs = util.fs();
var changes = 0;
var watcher = fs.watch(filenameTwo, function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal(filenameTwo);
watcher.close();
done();
});
fs.writeFile(filenameTwo, 'pardner');
});
it('should allow watches on dirs', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
if(error) throw error;
var watcher = fs.watch('/tmp', function(event, filename) {
// TODO: node thinks this should be 'rename', need to add rename along with change.
expect(event).to.equal('change');
expect(filename).to.equal(filenameTwo);
expect(filename).to.equal('/tmp');
watcher.close();
done();
});
fs.writeFile(filenameTwo, 'pardner');
});
it('should allow watches on dirs', function(done) {
var fs = util.fs();
fs.mkdir('/tmp', function(error) {
fs.open('/tmp/newfile.txt', 'w', function(error, fd) {
if(error) throw error;
var watcher = fs.watch('/tmp', function(event, filename) {
// TODO: node thinks this should be 'rename', need to add rename along with change.
expect(event).to.equal('change');
expect(filename).to.equal('/tmp');
watcher.close();
done();
});
fs.open('/tmp/newfile.txt', 'w', function(error, fd) {
if(error) throw error;
fs.close(fd);
});
fs.close(fd);
});
});
});

View File

@ -1,21 +1,45 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('path resolution', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('path resolution', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should follow a symbolic link to the root directory', function(done) {
var fs = util.fs();
it('should follow a symbolic link to the root directory', function(done) {
var fs = util.fs();
fs.symlink('/', '/mydirectorylink', function(error) {
fs.symlink('/', '/mydirectorylink', function(error) {
if(error) throw error;
fs.stat('/', function(error, result) {
if(error) throw error;
fs.stat('/', function(error, result) {
expect(result['node']).to.exist;
var _node = result['node'];
fs.stat('/mydirectorylink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.equal(_node);
done();
});
});
});
});
it('should follow a symbolic link to a directory', function(done) {
var fs = util.fs();
fs.mkdir('/mydir', function(error) {
fs.symlink('/mydir', '/mydirectorylink', function(error) {
if(error) throw error;
fs.stat('/mydir', function(error, result) {
if(error) throw error;
expect(result['node']).to.exist;
var _node = result['node'];
fs.stat('/mydirectorylink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
@ -25,20 +49,25 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should follow a symbolic link to a directory', function(done) {
var fs = util.fs();
it('should follow a symbolic link to a file', function(done) {
var fs = util.fs();
fs.mkdir('/mydir', function(error) {
fs.symlink('/mydir', '/mydirectorylink', function(error) {
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
fs.stat('/mydir', function(error, result) {
expect(result['node']).to.exist;
var _node = result['node'];
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
expect(result['node']).to.exist;
var _node = result['node'];
fs.stat('/mydirectorylink', function(error, result) {
fs.stat('/myfilelink', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.equal(_node);
@ -48,24 +77,27 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should follow a symbolic link to a file', function(done) {
var fs = util.fs();
it('should follow multiple symbolic links to a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
fs.stat('/myfile', function(error, result) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result['node']).to.exist;
var _node = result['node'];
fs.symlink('/myfile', '/myfilelink', function(error) {
expect(result['node']).to.exist;
var _node = result['node'];
fs.symlink('/myfile', '/myfilelink1', function(error) {
if(error) throw error;
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
if(error) throw error;
fs.stat('/myfilelink', function(error, result) {
fs.stat('/myfilelink2', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.equal(_node);
@ -76,151 +108,119 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
it('should follow multiple symbolic links to a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result['node']).to.exist;
var _node = result['node'];
fs.symlink('/myfile', '/myfilelink1', function(error) {
if(error) throw error;
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
if(error) throw error;
fs.stat('/myfilelink2', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result['node']).to.equal(_node);
done();
});
});
});
});
});
});
});
it('should error if symbolic link leads to itself', function(done) {
var fs = util.fs();
fs.symlink('/mylink1', '/mylink2', function(error) {
if(error) throw error;
fs.symlink('/mylink2', '/mylink1', function(error) {
if(error) throw error;
fs.stat('/myfilelink1', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
});
});
it('should error if it follows more than 10 symbolic links', function(done) {
var fs = util.fs();
var nlinks = 11;
function createSymlinkChain(n, callback) {
if(n > nlinks) {
return callback();
}
fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
}
fs.open('/myfile0', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile0', function(error, result) {
if(error) throw error;
createSymlinkChain(1, function() {
fs.stat('/myfile11', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal('ELOOP');
expect(result).not.to.exist;
done();
});
});
});
});
});
});
it('should follow a symbolic link in the path to a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
var _node = result['node'];
fs.symlink('/', '/mydirlink', function(error) {
if(error) throw error;
fs.stat('/mydirlink/myfile', function(error, result) {
expect(result).to.exist;
expect(error).not.to.exist;
expect(_node).to.exist;
expect(result['node']).to.equal(_node);
done();
});
});
});
});
});
});
it('should error if a symbolic link in the path to a file is itself a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
fs.open('/myfile2', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
if(error) throw error;
fs.stat('/mynotdirlink/myfile', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
expect(result).not.to.exist;
done();
});
});
});
});
});
});
});
});
});
it('should error if symbolic link leads to itself', function(done) {
var fs = util.fs();
fs.symlink('/mylink1', '/mylink2', function(error) {
if(error) throw error;
fs.symlink('/mylink2', '/mylink1', function(error) {
if(error) throw error;
fs.stat('/myfilelink1', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(result).not.to.exist;
done();
});
});
});
});
it('should error if it follows more than 10 symbolic links', function(done) {
var fs = util.fs();
var nlinks = 11;
function createSymlinkChain(n, callback) {
if(n > nlinks) {
return callback();
}
fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
}
fs.open('/myfile0', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile0', function(error, result) {
if(error) throw error;
createSymlinkChain(1, function() {
fs.stat('/myfile11', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal('ELOOP');
expect(result).not.to.exist;
done();
});
});
});
});
});
});
it('should follow a symbolic link in the path to a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
var _node = result['node'];
fs.symlink('/', '/mydirlink', function(error) {
if(error) throw error;
fs.stat('/mydirlink/myfile', function(error, result) {
expect(result).to.exist;
expect(error).not.to.exist;
expect(_node).to.exist;
expect(result['node']).to.equal(_node);
done();
});
});
});
});
});
});
it('should error if a symbolic link in the path to a file is itself a file', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
fs.open('/myfile2', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
if(error) throw error;
fs.stat('/mynotdirlink/myfile', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
expect(result).not.to.exist;
done();
});
});
});
});
});
});
});
});
});

View File

@ -1,15 +1,10 @@
define(["Filer", "util"], function(Filer, util) {
if(!Filer.FileSystem.providers.IndexedDB.isSupported()) {
console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since IndexedDB isn't supported.");
return;
}
if(navigator.userAgent.indexOf('PhantomJS') > -1) {
console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since PhantomJS doesn't support it.");
return;
}
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
if(!Filer.FileSystem.providers.IndexedDB.isSupported()) {
console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since IndexedDB isn't supported.");
} else {
describe("Filer.FileSystem.providers.IndexedDB", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(Filer.FileSystem.providers.IndexedDB.isSupported()).to.be.true;
@ -150,4 +145,4 @@ define(["Filer", "util"], function(Filer, util) {
});
});
}

View File

@ -1,114 +1,113 @@
define(["Filer"], function(Filer) {
var Filer = require('../../..');
var expect = require('chai').expect;
describe("Filer.FileSystem.providers.Memory", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(Filer.FileSystem.providers.Memory.isSupported()).to.be.true;
describe("Filer.FileSystem.providers.Memory", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(Filer.FileSystem.providers.Memory.isSupported()).to.be.true;
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var memoryProvider = new Filer.FileSystem.providers.Memory();
expect(memoryProvider.open).to.be.a('function');
expect(memoryProvider.getReadOnlyContext).to.be.a('function');
expect(memoryProvider.getReadWriteContext).to.be.a('function');
});
describe("open an Memory provider", function() {
it("should open a new Memory database", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
expect(error).not.to.exist;
expect(firstAccess).to.be.true;
done();
});
});
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var memoryProvider = new Filer.FileSystem.providers.Memory();
expect(memoryProvider.open).to.be.a('function');
expect(memoryProvider.getReadOnlyContext).to.be.a('function');
expect(memoryProvider.getReadWriteContext).to.be.a('function');
});
describe("Read/Write operations on an Memory provider", function() {
it("should allow put() and get()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
describe("open an Memory provider", function() {
it("should open a new Memory database", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
expect(error).not.to.exist;
expect(firstAccess).to.be.true;
done();
var context = provider.getReadWriteContext();
context.put("key", "value", function(error, result) {
if(error) throw error;
context.get("key", function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal("value");
done();
});
});
});
});
describe("Read/Write operations on an Memory provider", function() {
it("should allow put() and get()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
it("should allow delete()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.put("key", "value", function(error, result) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.put("key", "value", function(error, result) {
context.delete("key", function(error, result) {
if(error) throw error;
context.get("key", function(error, result) {
expect(error).not.to.exist;
expect(result).to.equal("value");
expect(result).not.to.exist;
done();
});
});
});
});
});
it("should allow delete()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
it("should allow clear()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(error, result) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.put("key", "value", function(error, result) {
context.put("key2", "value2", function(error, result) {
if(error) throw error;
context.delete("key", function(error, result) {
context.clear(function(err) {
if(error) throw error;
context.get("key", function(error, result) {
expect(error).not.to.exist;
expect(result).not.to.exist;
done();
});
});
});
});
});
it("should allow clear()", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(error, result) {
if(error) throw error;
context.put("key2", "value2", function(error, result) {
if(error) throw error;
context.clear(function(err) {
context.get("key1", function(error, result) {
if(error) throw error;
expect(result).not.to.exist;
context.get("key1", function(error, result) {
context.get("key2", function(error, result) {
if(error) throw error;
expect(result).not.to.exist;
context.get("key2", function(error, result) {
if(error) throw error;
expect(result).not.to.exist;
done();
});
done();
});
});
});
});
});
});
});
it("should fail when trying to write on ReadOnlyContext", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
it("should fail when trying to write on ReadOnlyContext", function(done) {
var provider = new Filer.FileSystem.providers.Memory();
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(error, result) {
expect(error).to.exist;
expect(result).not.to.exist;
done();
});
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(error, result) {
expect(error).to.exist;
expect(result).not.to.exist;
done();
});
});
});
});
});

View File

@ -1,27 +1,28 @@
define(["Filer"], function(Filer) {
describe("Filer.FileSystem.providers", function() {
it("is defined", function() {
expect(Filer.FileSystem.providers).to.exist;
});
var Filer = require('../../..');
var expect = require('chai').expect;
it("has IndexedDB constructor", function() {
expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function');
});
describe("Filer.FileSystem.providers", function() {
it("is defined", function() {
expect(Filer.FileSystem.providers).to.exist;
});
it("has WebSQL constructor", function() {
expect(Filer.FileSystem.providers.WebSQL).to.be.a('function');
});
it("has IndexedDB constructor", function() {
expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function');
});
it("has Memory constructor", function() {
expect(Filer.FileSystem.providers.Memory).to.be.a('function');
});
it("has WebSQL constructor", function() {
expect(Filer.FileSystem.providers.WebSQL).to.be.a('function');
});
it("has a Default constructor", function() {
expect(Filer.FileSystem.providers.Default).to.be.a('function');
});
it("has Memory constructor", function() {
expect(Filer.FileSystem.providers.Memory).to.be.a('function');
});
it("has Fallback constructor", function() {
expect(Filer.FileSystem.providers.Fallback).to.be.a('function');
});
it("has a Default constructor", function() {
expect(Filer.FileSystem.providers.Default).to.be.a('function');
});
it("has Fallback constructor", function() {
expect(Filer.FileSystem.providers.Fallback).to.be.a('function');
});
});

View File

@ -1,15 +1,10 @@
define(["Filer", "util"], function(Filer, util) {
if(!Filer.FileSystem.providers.WebSQL.isSupported()) {
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since WebSQL isn't supported.");
return;
}
if(navigator.userAgent.indexOf('PhantomJS') > -1) {
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since PhantomJS doesn't support it.");
return;
}
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
if(!Filer.FileSystem.providers.WebSQL.isSupported()) {
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since WebSQL isn't supported.");
} else {
describe("Filer.FileSystem.providers.WebSQL", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(Filer.FileSystem.providers.WebSQL.isSupported()).to.be.true;
@ -145,4 +140,4 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
}

View File

@ -1,84 +1,84 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.cat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.cat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.cat).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.cat).to.be.a('function');
});
it('should fail when files argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.cat(null, function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(data).not.to.exist;
done();
});
});
it('should fail when files argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should return the contents of a single file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
shell.cat(null, function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(data).not.to.exist;
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
shell.cat('/file', function(err, data) {
expect(err).not.to.exist;
expect(data).to.equal(contents);
done();
});
});
});
it('should return the contents of a single file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
it('should return the contents of multiple files', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
var contents2 = contents + '\n' + contents;
fs.writeFile('/file', contents, function(err) {
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/file2', contents2, function(err) {
if(err) throw err;
shell.cat('/file', function(err, data) {
shell.cat(['/file', '/file2'], function(err, data) {
expect(err).not.to.exist;
expect(data).to.equal(contents);
expect(data).to.equal(contents + '\n' + contents2);
done();
});
});
});
});
it('should return the contents of multiple files', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
var contents2 = contents + '\n' + contents;
it('should fail if any of multiple file paths is invalid', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
var contents2 = contents + '\n' + contents;
fs.writeFile('/file', contents, function(err) {
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/file2', contents2, function(err) {
if(err) throw err;
fs.writeFile('/file2', contents2, function(err) {
if(err) throw err;
shell.cat(['/file', '/file2'], function(err, data) {
expect(err).not.to.exist;
expect(data).to.equal(contents + '\n' + contents2);
done();
});
shell.cat(['/file', '/nofile'], function(err, data) {
expect(err).to.exist;
expect(err.code).to.equal("ENOENT");
expect(data).not.to.exist;
done();
});
});
});
it('should fail if any of multiple file paths is invalid', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "file contents";
var contents2 = contents + '\n' + contents;
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/file2', contents2, function(err) {
if(err) throw err;
shell.cat(['/file', '/nofile'], function(err, data) {
expect(err).to.exist;
expect(err.code).to.equal("ENOENT");
expect(data).not.to.exist;
done();
});
});
});
});
});
});

View File

@ -1,123 +1,122 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
describe('FileSystemShell.cd', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.cd', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.cd).to.be.a('function');
});
it('should be a function', function() {
var shell = util.shell();
expect(shell.cd).to.be.a('function');
});
it('should default to a cwd of /', function() {
var shell = util.shell();
expect(shell.pwd()).to.equal('/');
});
it('should allow changing the path to a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
it('should default to a cwd of /', function() {
var shell = util.shell();
expect(shell.pwd()).to.equal('/');
});
it('should allow changing the path to a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('/dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
shell.cd('/dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
});
});
it('should fail when changing the path to an invalid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should fail when changing the path to an invalid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('/nodir', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
expect(shell.pwd()).to.equal('/');
shell.cd('/nodir', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
done();
});
});
});
it('should fail when changing the path to a file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.writeFile('/file', 'file', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('/file', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
expect(shell.pwd()).to.equal('/');
done();
});
});
});
it('should allow relative paths for a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
});
});
it('should allow .. in paths for a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
shell.cd('..', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/');
done();
});
});
});
});
it('should fail when changing the path to a file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should follow symlinks to dirs', function(done) {
var fs = util.fs();
fs.writeFile('/file', 'file', function(err) {
if(err) throw err;
fs.mkdir('/dir', function(error) {
if(error) throw error;
expect(shell.pwd()).to.equal('/');
shell.cd('/file', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
expect(shell.pwd()).to.equal('/');
done();
});
});
});
it('should allow relative paths for a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
});
});
it('should allow .. in paths for a valid dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
shell.cd('..', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/');
done();
});
});
});
});
it('should follow symlinks to dirs', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(error) {
fs.symlink('/dir', '/link', function(error) {
if(error) throw error;
fs.symlink('/dir', '/link', function(error) {
if(error) throw error;
var shell = fs.Shell();
shell.cd('link', function(error) {
expect(error).not.to.exist;
expect(shell.pwd()).to.equal('/link');
done();
});
var shell = fs.Shell();
shell.cd('link', function(error) {
expect(error).not.to.exist;
expect(shell.pwd()).to.equal('/link');
done();
});
});
});
});
});

View File

@ -1,113 +1,113 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.env', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.env', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should get default env options', function() {
var shell = util.shell();
expect(shell.env).to.exist;
expect(shell.env.get('TMP')).to.equal('/tmp');
expect(shell.env.get('PATH')).to.equal('');
expect(shell.pwd()).to.equal('/');
it('should get default env options', function() {
var shell = util.shell();
expect(shell.env).to.exist;
expect(shell.env.get('TMP')).to.equal('/tmp');
expect(shell.env.get('PATH')).to.equal('');
expect(shell.pwd()).to.equal('/');
});
it('should be able to specify env options', function() {
var options = {
env: {
TMP: '/tempdir',
PATH: '/dir'
}
};
var shell = util.shell(options);
expect(shell.env).to.exist;
expect(shell.env.get('TMP')).to.equal('/tempdir');
expect(shell.env.get('PATH')).to.equal('/dir');
expect(shell.pwd()).to.equal('/');
expect(shell.env.get('FOO')).not.to.exist;
shell.env.set('FOO', 1);
expect(shell.env.get('FOO')).to.equal(1);
});
it('should fail when dirs argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
done();
});
});
it('should give new value for shell.pwd() when cwd changes', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
it('should be able to specify env options', function() {
var options = {
env: {
TMP: '/tempdir',
PATH: '/dir'
}
};
var shell = util.shell(options);
expect(shell.env).to.exist;
expect(shell.env.get('TMP')).to.equal('/tempdir');
expect(shell.env.get('PATH')).to.equal('/dir');
expect(shell.pwd()).to.equal('/');
expect(shell.env.get('FOO')).not.to.exist;
shell.env.set('FOO', 1);
expect(shell.env.get('FOO')).to.equal(1);
});
it('should fail when dirs argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
shell.cd('/dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
});
});
it('should give new value for shell.pwd() when cwd changes', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should create/return the default tmp dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
expect(shell.pwd()).to.equal('/');
shell.cd('/dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
});
});
});
it('should create/return the default tmp dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) {
expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) {
expect(err).not.to.exist;
shell.cd(tmp, function(err) {
expect(err).not.to.exist;
shell.cd(tmp, function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/tmp');
done();
});
expect(shell.pwd()).to.equal('/tmp');
done();
});
});
});
it('should create/return the tmp dir specified in env.TMP', function(done) {
var fs = util.fs();
var shell = fs.Shell({
env: {
TMP: '/tempdir'
}
});
it('should create/return the tmp dir specified in env.TMP', function(done) {
var fs = util.fs();
var shell = fs.Shell({
env: {
TMP: '/tempdir'
}
});
expect(shell.env.get('TMP')).to.equal('/tempdir');
shell.tempDir(function(err, tmp) {
expect(shell.env.get('TMP')).to.equal('/tempdir');
shell.tempDir(function(err, tmp) {
expect(err).not.to.exist;
shell.cd(tmp, function(err) {
expect(err).not.to.exist;
shell.cd(tmp, function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/tempdir');
done();
});
expect(shell.pwd()).to.equal('/tempdir');
done();
});
});
});
it('should allow repeated calls to tempDir()', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should allow repeated calls to tempDir()', function(done) {
var fs = util.fs();
var shell = fs.Shell();
expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) {
expect(err).not.to.exist;
expect(tmp).to.equal('/tmp');
expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) {
expect(err).not.to.exist;
expect(tmp).to.equal('/tmp');
shell.tempDir(function(err, tmp) {
expect(err).not.to.exist;
expect(tmp).to.equal('/tmp');
done();
});
done();
});
});
});
});

View File

@ -1,33 +1,33 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.exec', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.exec', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.exec).to.be.a('function');
});
it('should be a function', function() {
var shell = util.shell();
expect(shell.exec).to.be.a('function');
});
it('should be able to execute a command .js file from the filesystem', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var cmdString = "fs.writeFile(args[0], args[1], callback);";
it('should be able to execute a command .js file from the filesystem', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var cmdString = "fs.writeFile(args[0], args[1], callback);";
fs.writeFile('/cmd.js', cmdString, function(error) {
fs.writeFile('/cmd.js', cmdString, function(error) {
if(error) throw error;
shell.exec('/cmd.js', ['/test', 'hello world'], function(error, result) {
if(error) throw error;
shell.exec('/cmd.js', ['/test', 'hello world'], function(error, result) {
fs.readFile('/test', 'utf8', function(error, data) {
if(error) throw error;
fs.readFile('/test', 'utf8', function(error, data) {
if(error) throw error;
expect(data).to.equal('hello world');
done();
});
expect(data).to.equal('hello world');
done();
});
});
});
});
});

View File

@ -1,73 +1,134 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.ls', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.ls', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.ls).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.ls).to.be.a('function');
});
it('should fail when dirs argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
done();
});
});
it('should fail when dirs argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should return the contents of a simple dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
var contents2 = "bb";
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
done();
});
});
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
it('should return the contents of a simple dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
var contents2 = "bb";
fs.writeFile('/file', contents, function(err) {
fs.writeFile('/file2', contents2, function(err) {
if(err) throw err;
fs.writeFile('/file2', contents2, function(err) {
shell.ls('/', function(err, list) {
expect(err).not.to.exist;
expect(list.length).to.equal(2);
var item0 = list[0];
expect(item0.path).to.equal('file');
expect(item0.links).to.equal(1);
expect(item0.size).to.equal(1);
expect(item0.modified).to.be.a('number');
expect(item0.type).to.equal('FILE');
expect(item0.contents).not.to.exist;
var item1 = list[1];
expect(item1.path).to.equal('file2');
expect(item1.links).to.equal(1);
expect(item1.size).to.equal(2);
expect(item1.modified).to.be.a('number');
expect(item1.type).to.equal('FILE');
expect(item0.contents).not.to.exist;
done();
});
});
});
});
it('should return the shallow contents of a dir tree', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
if(err) throw err;
fs.writeFile('/dir/file', contents, function(err) {
if(err) throw err;
shell.ls('/', function(err, list) {
expect(err).not.to.exist;
expect(list.length).to.equal(2);
fs.writeFile('/dir/file2', contents, function(err) {
if(err) throw err;
var item0 = list[0];
expect(item0.path).to.equal('file');
expect(item0.links).to.equal(1);
expect(item0.size).to.equal(1);
expect(item0.modified).to.be.a('number');
expect(item0.type).to.equal('FILE');
expect(item0.contents).not.to.exist;
shell.ls('/dir', function(err, list) {
expect(err).not.to.exist;
expect(list.length).to.equal(3);
var item1 = list[1];
expect(item1.path).to.equal('file2');
expect(item1.links).to.equal(1);
expect(item1.size).to.equal(2);
expect(item1.modified).to.be.a('number');
expect(item1.type).to.equal('FILE');
expect(item0.contents).not.to.exist;
// We shouldn't rely on the order we'll get the listing
list.forEach(function(item, i, arr) {
switch(item.path) {
case 'dir2':
expect(item.links).to.equal(1);
expect(item.size).to.be.a('number');
expect(item.modified).to.be.a('number');
expect(item.type).to.equal('DIRECTORY');
expect(item.contents).not.to.exist;
break;
case 'file':
case 'file2':
expect(item.links).to.equal(1);
expect(item.size).to.equal(1);
expect(item.modified).to.be.a('number');
expect(item.type).to.equal('FILE');
expect(item.contents).not.to.exist;
break;
default:
// shouldn't happen
expect(true).to.be.false;
break;
}
done();
if(i === arr.length -1) {
done();
}
});
});
});
});
});
});
});
it('should return the shallow contents of a dir tree', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
it('should return the deep contents of a dir tree', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
fs.mkdir('/dir', function(err) {
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
fs.writeFile('/dir/dir2/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/dir/file', contents, function(err) {
@ -76,7 +137,7 @@ define(["Filer", "util"], function(Filer, util) {
fs.writeFile('/dir/file2', contents, function(err) {
if(err) throw err;
shell.ls('/dir', function(err, list) {
shell.ls('/dir', { recursive: true }, function(err, list) {
expect(err).not.to.exist;
expect(list.length).to.equal(3);
@ -88,7 +149,15 @@ define(["Filer", "util"], function(Filer, util) {
expect(item.size).to.be.a('number');
expect(item.modified).to.be.a('number');
expect(item.type).to.equal('DIRECTORY');
expect(item.contents).not.to.exist;
expect(item.contents).to.exist;
expect(item.contents.length).to.equal(1);
var contents0 = item.contents[0];
expect(contents0.path).to.equal('file');
expect(contents0.links).to.equal(1);
expect(contents0.size).to.equal(1);
expect(contents0.modified).to.be.a('number');
expect(contents0.type).to.equal('FILE');
expect(contents0.contents).not.to.exist;
break;
case 'file':
case 'file2':
@ -114,74 +183,5 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
it('should return the deep contents of a dir tree', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
if(err) throw err;
fs.writeFile('/dir/dir2/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/dir/file', contents, function(err) {
if(err) throw err;
fs.writeFile('/dir/file2', contents, function(err) {
if(err) throw err;
shell.ls('/dir', { recursive: true }, function(err, list) {
expect(err).not.to.exist;
expect(list.length).to.equal(3);
// We shouldn't rely on the order we'll get the listing
list.forEach(function(item, i, arr) {
switch(item.path) {
case 'dir2':
expect(item.links).to.equal(1);
expect(item.size).to.be.a('number');
expect(item.modified).to.be.a('number');
expect(item.type).to.equal('DIRECTORY');
expect(item.contents).to.exist;
expect(item.contents.length).to.equal(1);
var contents0 = item.contents[0];
expect(contents0.path).to.equal('file');
expect(contents0.links).to.equal(1);
expect(contents0.size).to.equal(1);
expect(contents0.modified).to.be.a('number');
expect(contents0.type).to.equal('FILE');
expect(contents0.contents).not.to.exist;
break;
case 'file':
case 'file2':
expect(item.links).to.equal(1);
expect(item.size).to.equal(1);
expect(item.modified).to.be.a('number');
expect(item.type).to.equal('FILE');
expect(item.contents).not.to.exist;
break;
default:
// shouldn't happen
expect(true).to.be.false;
break;
}
if(i === arr.length -1) {
done();
}
});
});
});
});
});
});
});
});
});
});

View File

@ -1,97 +1,98 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.mkdirp', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.mkdirp', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.mkdirp).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.mkdirp).to.be.a('function');
});
it('should fail without a path provided', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp(null, function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
});
});
it('should fail without a path provided', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should succeed if provided path is root', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/', function(err) {
expect(err).to.not.exist;
done();
});
});
shell.mkdirp(null, function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
it('should succeed if the directory exists', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test',function(err) {
expect(err).to.not.exist;
done();
});
});
});
it('should succeed if provided path is root', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/', function(err) {
expect(err).to.not.exist;
done();
it('fail if a file name is provided', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test.txt', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
done();
});
});
});
it('should succeed if the directory exists', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test',function(err) {
expect(err).to.not.exist;
done();
});
});
});
it('fail if a file name is provided', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test.txt', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
done();
});
it('should succeed on a folder on root (\'/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir){
expect(dir).to.be.true;
done();
});
});
});
it('should succeed on a folder on root (\'/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir){
expect(dir).to.be.true;
done();
});
});
});
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/test/test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir1){
expect(dir1).to.be.true;
fs.exists('/test/test', function(dir2){
expect(dir2).to.be.true;
done();
});
});
});
});
it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test.txt/test', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.mkdirp('/test/test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir1){
expect(dir1).to.be.true;
fs.exists('/test/test', function(dir2){
expect(dir2).to.be.true;
done();
});
});
});
});
it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist;
shell.mkdirp('/test.txt/test', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
done();
});
});
});
});

View File

@ -1,54 +1,97 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.rm', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.rm', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.rm).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.rm).to.be.a('function');
});
it('should fail when path argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.rm(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
done();
});
});
it('should fail when path argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should remove a single file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
shell.rm(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(list).not.to.exist;
done();
});
});
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
it('should remove a single file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
shell.rm('/file', function(err) {
expect(err).not.to.exist;
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
shell.rm('/file', function(err) {
expect(err).not.to.exist;
fs.stat('/file', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
fs.stat('/file', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
});
});
});
it('should remove an empty dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should remove an empty dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
fs.mkdir('/dir', function(err) {
if(err) throw err;
shell.rm('/dir', function(err) {
expect(err).not.to.exist;
fs.stat('/dir', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
});
});
});
it('should fail to remove a non-empty dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
shell.touch('/dir/file', function(err) {
if(err) throw err;
shell.rm('/dir', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTEMPTY');
done();
});
});
});
});
it('should remove a non-empty dir with option.recursive set', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
shell.touch('/dir/file', function(err) {
if(err) throw err;
shell.rm('/dir', { recursive: true }, function(err) {
expect(err).not.to.exist;
fs.stat('/dir', function(err, stats) {
@ -59,80 +102,37 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should fail to remove a non-empty dir', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should work on a complex dir structure', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
fs.mkdir('/dir', function(err) {
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
if(err) throw err;
shell.touch('/dir/file', function(err) {
fs.writeFile('/dir/file', contents, function(err) {
if(err) throw err;
shell.rm('/dir', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTEMPTY');
done();
});
});
});
});
it('should remove a non-empty dir with option.recursive set', function(done) {
var fs = util.fs();
var shell = fs.Shell();
fs.mkdir('/dir', function(err) {
if(err) throw err;
shell.touch('/dir/file', function(err) {
if(err) throw err;
shell.rm('/dir', { recursive: true }, function(err) {
expect(err).not.to.exist;
fs.stat('/dir', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
});
});
});
});
it('should work on a complex dir structure', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var contents = "a";
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.mkdir('/dir/dir2', function(err) {
if(err) throw err;
fs.writeFile('/dir/file', contents, function(err) {
fs.writeFile('/dir/file2', contents, function(err) {
if(err) throw err;
fs.writeFile('/dir/file2', contents, function(err) {
if(err) throw err;
shell.rm('/dir', { recursive: true }, function(err) {
expect(err).not.to.exist;
shell.rm('/dir', { recursive: true }, function(err) {
expect(err).not.to.exist;
fs.stat('/dir', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
fs.stat('/dir', function(err, stats) {
expect(err).to.exist;
expect(stats).not.to.exist;
done();
});
});
});
});
});
});
});
});

View File

@ -1,98 +1,76 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
function getTimes(fs, path, callback) {
fs.stat(path, function(error, stats) {
function getTimes(fs, path, callback) {
fs.stat(path, function(error, stats) {
if(error) throw error;
callback({mtime: stats.mtime, atime: stats.atime});
});
}
describe('FileSystemShell.touch', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.touch).to.be.a('function');
});
it('should create a new file if path does not exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.touch('/newfile', function(error) {
if(error) throw error;
callback({mtime: stats.mtime, atime: stats.atime});
fs.stat('/newfile', function(error, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('FILE');
done();
});
});
}
});
describe('FileSystemShell.touch', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should skip creating a new file if options.updateOnly is true', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should be a function', function() {
var shell = util.shell();
expect(shell.touch).to.be.a('function');
shell.touch('/newfile', { updateOnly: true }, function(error) {
if(error) throw error;
fs.stat('/newfile', function(error, stats) {
expect(error).to.exist;
done();
});
});
});
it('should create a new file if path does not exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should update times if path does exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
shell.touch('/newfile', function(error) {
fs.open('/newfile', 'w', function (error, fd) {
if (error) throw error;
fs.futimes(fd, atime, mtime, function (error) {
if(error) throw error;
fs.stat('/newfile', function(error, stats) {
expect(error).not.to.exist;
expect(stats.type).to.equal('FILE');
done();
});
});
});
it('should skip creating a new file if options.updateOnly is true', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.touch('/newfile', { updateOnly: true }, function(error) {
if(error) throw error;
fs.stat('/newfile', function(error, stats) {
expect(error).to.exist;
done();
});
});
});
it('should update times if path does exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.open('/newfile', 'w', function (error, fd) {
if (error) throw error;
fs.futimes(fd, atime, mtime, function (error) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
getTimes(fs, '/newfile', function(times1) {
shell.touch('/newfile', function(error) {
expect(error).not.to.exist;
getTimes(fs, '/newfile', function(times2) {
expect(times2.mtime).to.be.above(times1.mtime);
expect(times2.atime).to.be.above(times1.atime);
done();
});
});
});
});
});
});
});
it('should update times to specified date if path does exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var date = Date.parse('1 Oct 2001 15:33:22');
fs.open('/newfile', 'w', function (error, fd) {
if (error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
shell.touch('/newfile', { date: date }, function(error) {
expect(error).not.to.exist;
getTimes(fs, '/newfile', function(times1) {
shell.touch('/newfile', function(error) {
expect(error).not.to.exist;
getTimes(fs, '/newfile', function(times) {
expect(times.mtime).to.equal(date);
done();
getTimes(fs, '/newfile', function(times2) {
expect(times2.mtime).to.be.above(times1.mtime);
expect(times2.atime).to.be.above(times1.atime);
done();
});
});
});
});
@ -100,4 +78,26 @@ define(["Filer", "util"], function(Filer, util) {
});
});
it('should update times to specified date if path does exist', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var date = Date.parse('1 Oct 2001 15:33:22');
fs.open('/newfile', 'w', function (error, fd) {
if (error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
shell.touch('/newfile', { date: date }, function(error) {
expect(error).not.to.exist;
getTimes(fs, '/newfile', function(times) {
expect(times.mtime).to.equal(date);
done();
});
});
});
});
});
});

View File

@ -1,96 +1,95 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.wget', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.wget', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.wget).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.wget).to.be.a('function');
});
it('should fail when url argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.wget(null, function(err, data) {
expect(err).to.exist;
expect(data).not.to.exist;
done();
});
});
it('should fail when url argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should fail when the url does not exist (404)', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.wget(null, function(err, data) {
expect(err).to.exist;
expect(data).not.to.exist;
shell.wget("no-such-url", function(err, data) {
expect(err).to.exist;
expect(data).not.to.exist;
done();
});
});
it('should download the contents of a file from a url to default filename', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
var contents = "This is a test file used in some of the tests.\n";
shell.wget(url, function(err, path) {
if(err) throw err;
expect(path).to.equal('/test-file.txt');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
it('should fail when the url does not exist (404)', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should download the contents of a file from a url to specified filename', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
var contents = "This is a test file used in some of the tests.\n";
shell.wget("no-such-url", function(err, data) {
expect(err).to.exist;
expect(data).not.to.exist;
shell.wget(url, { filename: 'test-file.txt' }, function(err, path) {
if(err) throw err;
expect(path).to.equal('/test-file.txt');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
it('should download the contents of a file from a url to default filename', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
var contents = "This is a test file used in some of the tests.\n";
it('should download the contents of a file from a url with query string', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt?foo" : "/tests/test-file.txt?foo";
var contents = "This is a test file used in some of the tests.\n";
shell.wget(url, function(err, path) {
shell.wget(url, function(err, path) {
if(err) throw err;
expect(path).to.equal('/test-file.txt?foo');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(path).to.equal('/test-file.txt');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
expect(data).to.equal(contents);
done();
});
});
it('should download the contents of a file from a url to specified filename', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
var contents = "This is a test file used in some of the tests.\n";
shell.wget(url, { filename: 'test-file.txt' }, function(err, path) {
if(err) throw err;
expect(path).to.equal('/test-file.txt');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
it('should download the contents of a file from a url with query string', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt?foo" : "/tests/test-file.txt?foo";
var contents = "This is a test file used in some of the tests.\n";
shell.wget(url, function(err, path) {
if(err) throw err;
expect(path).to.equal('/test-file.txt?foo');
fs.readFile(path, 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
});
});

View File

@ -1,46 +1,82 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../../..');
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
describe('FileSystemShell.zip() and unzip()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
describe('FileSystemShell.zip() and unzip()', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var shell = util.shell();
expect(shell.zip).to.be.a('function');
expect(shell.unzip).to.be.a('function');
it('should be a function', function() {
var shell = util.shell();
expect(shell.zip).to.be.a('function');
expect(shell.unzip).to.be.a('function');
});
it('should fail when path argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
shell.unzip(null, function(err) {
expect(err).to.exist;
done();
});
});
it('should fail when path argument is absent', function(done) {
var fs = util.fs();
var shell = fs.Shell();
it('should download and unzip the contents of a zip file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip";
var filename = "test-file.txt.zip";
var contents = "This is a test file used in some of the tests.\n";
shell.unzip(null, function(err) {
expect(err).to.exist;
done();
});
});
fs.writeFile('/original', contents, function(err) {
if(err) throw err;
it('should download and unzip the contents of a zip file', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip";
var filename = "test-file.txt.zip";
var contents = "This is a test file used in some of the tests.\n";
fs.writeFile('/original', contents, function(err) {
shell.wget(url, {filename: filename}, function(err, path) {
if(err) throw err;
shell.wget(url, {filename: filename}, function(err, path) {
shell.unzip(path, function(err) {
if(err) throw err;
shell.unzip(path, function(err) {
fs.readFile('/original', function(err, originalData) {
if(err) throw err;
fs.readFile('/test-file.txt', function(err, data) {
if(err) throw err;
expect(util.typedArrayEqual(data, originalData)).to.be.true;
done();
});
});
});
});
});
});
it('should download and unzip the contents of a zip file with a specified destination', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var Path = Filer.Path;
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip";
var filename = "test-file.txt.zip";
var contents = "This is a test file used in some of the tests.\n";
fs.writeFile('/original', contents, function(err) {
if(err) throw err;
shell.wget(url, {filename: filename}, function(err, path) {
if(err) throw err;
shell.tempDir(function(err, tmp) {
if (err) throw err;
shell.unzip(path, { destination: tmp }, function(err) {
if(err) throw err;
fs.readFile('/original', function(err, originalData) {
if(err) throw err;
fs.readFile('/test-file.txt', function(err, data) {
fs.readFile(Path.join(tmp, 'test-file.txt'), function(err, data) {
if(err) throw err;
expect(util.typedArrayEqual(data, originalData)).to.be.true;
done();
@ -50,33 +86,39 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should download and unzip the contents of a zip file with a specified destination', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var Path = Filer.Path;
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip";
var filename = "test-file.txt.zip";
var contents = "This is a test file used in some of the tests.\n";
it('should be able to zip and unzip a file', function(done) {
var fs = util.fs();
var file = '/test-file.txt';
var zipfile = file + '.zip';
var shell = fs.Shell();
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
fs.writeFile('/original', contents, function(err) {
fs.writeFile(file, contents, function(err) {
if(err) throw err;
shell.zip(zipfile, file, function(err) {
if(err) throw err;
shell.wget(url, {filename: filename}, function(err, path) {
fs.stat(zipfile, function(err, stats) {
if(err) throw err;
expect(stats.isFile()).to.be.true;
shell.tempDir(function(err, tmp) {
if (err) throw err;
shell.rm(file, function(err) {
if(err) throw err;
shell.unzip(path, { destination: tmp }, function(err) {
shell.unzip(zipfile, function(err) {
if(err) throw err;
fs.readFile('/original', function(err, originalData) {
fs.stat(file, function(err, stats) {
if(err) throw err;
expect(stats.isFile()).to.be.true;
fs.readFile(Path.join(tmp, 'test-file.txt'), function(err, data) {
fs.readFile(Path.join('/', file), 'utf8', function(err, data) {
if(err) throw err;
expect(util.typedArrayEqual(data, originalData)).to.be.true;
expect(data).to.equal(contents);
done();
});
});
@ -85,202 +127,159 @@ define(["Filer", "util"], function(Filer, util) {
});
});
});
});
it('should be able to zip and unzip a file', function(done) {
var fs = util.fs();
var file = '/test-file.txt';
var zipfile = file + '.zip';
var shell = fs.Shell();
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
it('should be able to handle a deep tree structure in a zip', function(done) {
// test-dir.zip has the following structure:
//
// test-dir/
// ├── test-dir2
// │ └── test-file.txt
// ├── test-file.txt
// └── test-file2.txt
fs.writeFile(file, contents, function(err) {
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip";
var filename = "test-dir.zip";
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
function confirmFile(filename, callback) {
filename = Path.join('/', filename);
fs.readFile(filename, 'utf8', function(err, data) {
if(err) {
console.error('Expected ' + filename + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(data).to.equal(contents);
callback();
});
}
function confirmDir(dirname, callback) {
dirname = Path.join('/', dirname);
fs.stat(dirname, function(err, stats) {
if(err) {
console.error('Expected ' + dirname + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(stats.isDirectory()).to.be.true;
callback();
});
}
shell.wget(url, {filename: filename}, function(err, path) {
if(err) throw err;
shell.unzip(path, function(err) {
if(err) throw err;
shell.zip(zipfile, file, function(err) {
if(err) throw err;
fs.stat(zipfile, function(err, stats) {
if(err) throw err;
expect(stats.isFile()).to.be.true;
shell.rm(file, function(err) {
if(err) throw err;
shell.unzip(zipfile, function(err) {
if(err) throw err;
fs.stat(file, function(err, stats) {
if(err) throw err;
expect(stats.isFile()).to.be.true;
fs.readFile(Path.join('/', file), 'utf8', function(err, data) {
if(err) throw err;
expect(data).to.equal(contents);
done();
});
});
});
});
});
});
// Forgive the crazy indenting, trying to match tree structure ;)
confirmDir('test-dir', function() {
confirmDir('test-dir/test-dir2', function() {
confirmFile('test-dir/test-dir2/test-file.txt', function() {
confirmFile('test-dir/test-file.txt', function() {
confirmFile('test-dir/test-file2.txt', function() {
done();
});});});});});
});
});
});
it('should be able to handle a deep tree structure in a zip', function(done) {
// test-dir.zip has the following structure:
//
// test-dir/
// ├── test-dir2
// │ └── test-file.txt
// ├── test-file.txt
// └── test-file2.txt
it('should be able to re-create (unzip/zip) a deep tree structure in a zip', function(done) {
// test-dir.zip has the following structure:
//
// test-dir/
// ├── test-dir2
// │ └── test-file.txt
// ├── test-file.txt
// └── test-file2.txt
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip";
var filename = "test-dir.zip";
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip";
var filename = "test-dir.zip";
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
function confirmFile(filename, callback) {
filename = Path.join('/', filename);
fs.readFile(filename, 'utf8', function(err, data) {
if(err) {
console.error('Expected ' + filename + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(data).to.equal(contents);
callback();
});
}
function confirmDir(dirname, callback) {
dirname = Path.join('/', dirname);
fs.stat(dirname, function(err, stats) {
if(err) {
console.error('Expected ' + dirname + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(stats.isDirectory()).to.be.true;
callback();
});
}
shell.wget(url, {filename: filename}, function(err, path) {
if(err) throw err;
shell.unzip(path, function(err) {
if(err) throw err;
// Forgive the crazy indenting, trying to match tree structure ;)
confirmDir('test-dir', function() {
confirmDir('test-dir/test-dir2', function() {
confirmFile('test-dir/test-dir2/test-file.txt', function() {
confirmFile('test-dir/test-file.txt', function() {
confirmFile('test-dir/test-file2.txt', function() {
done();
});});});});});
});
function confirmFile(filename, callback) {
filename = Path.join('/unzipped', filename);
fs.readFile(filename, 'utf8', function(err, data) {
if(err) {
console.error('Expected ' + filename + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(data).to.equal(contents);
callback();
});
});
}
it('should be able to re-create (unzip/zip) a deep tree structure in a zip', function(done) {
// test-dir.zip has the following structure:
//
// test-dir/
// ├── test-dir2
// │ └── test-file.txt
// ├── test-file.txt
// └── test-file2.txt
function confirmDir(dirname, callback) {
dirname = Path.join('/unzipped', dirname);
fs.stat(dirname, function(err, stats) {
if(err) {
console.error('Expected ' + dirname + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(stats.isDirectory()).to.be.true;
callback();
});
}
var fs = util.fs();
var shell = fs.Shell();
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip";
var filename = "test-dir.zip";
var Path = Filer.Path;
var contents = "This is a test file used in some of the tests.\n";
shell.wget(url, {filename: filename}, function(err, path) {
if(err) throw err;
function confirmFile(filename, callback) {
filename = Path.join('/unzipped', filename);
fs.readFile(filename, 'utf8', function(err, data) {
if(err) {
console.error('Expected ' + filename + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(data).to.equal(contents);
callback();
});
}
function confirmDir(dirname, callback) {
dirname = Path.join('/unzipped', dirname);
fs.stat(dirname, function(err, stats) {
if(err) {
console.error('Expected ' + dirname + ' to exist.');
expect(false).to.be.true;
return callback(err);
}
expect(stats.isDirectory()).to.be.true;
callback();
});
}
shell.wget(url, {filename: filename}, function(err, path) {
shell.unzip(path, function(err) {
if(err) throw err;
shell.unzip(path, function(err) {
shell.zip('/test-dir2.zip', '/test-dir', { recursive: true }, function(err) {
if(err) throw err;
shell.zip('/test-dir2.zip', '/test-dir', { recursive: true }, function(err) {
shell.mkdirp('/unzipped', function(err) {
if(err) throw err;
shell.mkdirp('/unzipped', function(err) {
shell.unzip('/test-dir2.zip', { destination: '/unzipped' }, function(err) {
if(err) throw err;
shell.unzip('/test-dir2.zip', { destination: '/unzipped' }, function(err) {
if(err) throw err;
// Forgive the crazy indenting, trying to match tree structure ;)
confirmDir('test-dir', function() {
confirmDir('test-dir/test-dir2', function() {
confirmFile('test-dir/test-dir2/test-file.txt', function() {
// Forgive the crazy indenting, trying to match tree structure ;)
confirmDir('test-dir', function() {
confirmDir('test-dir/test-dir2', function() {
confirmFile('test-dir/test-dir2/test-file.txt', function() {
confirmFile('test-dir/test-file.txt', function() {
confirmFile('test-dir/test-file2.txt', function() {
done();
});});});});});
});});});});});
});
});
});
});
});
});
});
it('should fail if the zipfile already exists', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var file = "/file";
var zipfile = "/zipfile.zip";
var contents = "This is a test file used in some of the tests.\n";
it('should fail if the zipfile already exists', function(done) {
var fs = util.fs();
var shell = fs.Shell();
var file = "/file";
var zipfile = "/zipfile.zip";
var contents = "This is a test file used in some of the tests.\n";
fs.writeFile(file, contents, function(err) {
fs.writeFile(file, contents, function(err) {
if(err) throw err;
shell.zip(zipfile, file, function(err) {
if(err) throw err;
shell.zip(zipfile, file, function(err) {
if(err) throw err;
shell.zip(zipfile, file, function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EEXIST');
done();
});
expect(err).to.exist;
expect(err.code).to.equal('EEXIST');
done();
});
});
});
});
});

View File

@ -1,106 +1,106 @@
define(["Filer", "util"], function(Filer, util) {
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('node times (atime, mtime, ctime) with mount flags', function() {
describe('node times (atime, mtime, ctime) with mount flags', function() {
var dirname = "/dir";
var filename = "/dir/file";
var dirname = "/dir";
var filename = "/dir/file";
function memoryFS(flags, callback) {
var name = util.uniqueName();
var fs = new Filer.FileSystem({
name: name,
flags: flags || [],
provider: new Filer.FileSystem.providers.Memory(name)
}, callback);
}
function memoryFS(flags, callback) {
var name = util.uniqueName();
var fs = new Filer.FileSystem({
name: name,
flags: flags || [],
provider: new Filer.FileSystem.providers.Memory(name)
}, callback);
}
function createTree(fs, callback) {
fs.mkdir(dirname, function(error) {
function createTree(fs, callback) {
fs.mkdir(dirname, function(error) {
if(error) throw error;
fs.open(filename, 'w', function(error, fd) {
if(error) throw error;
fs.open(filename, 'w', function(error, fd) {
if(error) throw error;
fs.close(fd, callback);
});
fs.close(fd, callback);
});
}
});
}
function stat(fs, path, callback) {
fs.stat(path, function(error, stats) {
if(error) throw error;
function stat(fs, path, callback) {
fs.stat(path, function(error, stats) {
if(error) throw error;
callback(stats);
});
}
callback(stats);
});
}
/**
* We test the actual time updates in times.spec.js, whereas these just test
* the overrides with the mount flags. The particular fs methods called
* are unimportant, but are known to affect the particular times being suppressed.
*/
/**
* We test the actual time updates in times.spec.js, whereas these just test
* the overrides with the mount flags. The particular fs methods called
* are unimportant, but are known to affect the particular times being suppressed.
*/
it('should not update ctime when calling fs.rename() with NOCTIME', function(done) {
memoryFS(['NOCTIME'], function(error, fs) {
var newfilename = filename + '1';
it('should not update ctime when calling fs.rename() with NOCTIME', function(done) {
memoryFS(['NOCTIME'], function(error, fs) {
var newfilename = filename + '1';
createTree(fs, function() {
stat(fs, filename, function(stats1) {
createTree(fs, function() {
stat(fs, filename, function(stats1) {
fs.rename(filename, newfilename, function(error) {
if(error) throw error;
fs.rename(filename, newfilename, function(error) {
if(error) throw error;
stat(fs, newfilename, function(stats2) {
expect(stats2.ctime).to.equal(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.equal(stats1.atime);
done();
});
stat(fs, newfilename, function(stats2) {
expect(stats2.ctime).to.equal(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.equal(stats1.atime);
done();
});
});
});
});
});
});
it('should not update ctime, mtime, atime when calling fs.truncate() with NOCTIME, NOMTIME', function(done) {
memoryFS(['NOCTIME', 'NOMTIME'], function(error, fs) {
createTree(fs, function() {
stat(fs, filename, function(stats1) {
it('should not update ctime, mtime, atime when calling fs.truncate() with NOCTIME, NOMTIME', function(done) {
memoryFS(['NOCTIME', 'NOMTIME'], function(error, fs) {
createTree(fs, function() {
stat(fs, filename, function(stats1) {
fs.truncate(filename, 5, function(error) {
if(error) throw error;
fs.truncate(filename, 5, function(error) {
if(error) throw error;
stat(fs, filename, function(stats2) {
expect(stats2.ctime).to.equal(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.equal(stats1.atime);
done();
});
stat(fs, filename, function(stats2) {
expect(stats2.ctime).to.equal(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.equal(stats1.atime);
done();
});
});
});
});
});
});
it('should not update mtime when calling fs.truncate() with NOMTIME', function(done) {
memoryFS(['NOMTIME'], function(error, fs) {
createTree(fs, function() {
stat(fs, filename, function(stats1) {
it('should not update mtime when calling fs.truncate() with NOMTIME', function(done) {
memoryFS(['NOMTIME'], function(error, fs) {
createTree(fs, function() {
stat(fs, filename, function(stats1) {
fs.truncate(filename, 5, function(error) {
if(error) throw error;
fs.truncate(filename, 5, function(error) {
if(error) throw error;
stat(fs, filename, function(stats2) {
expect(stats2.ctime).to.be.at.least(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.be.at.least(stats1.atime);
done();
});
stat(fs, filename, function(stats2) {
expect(stats2.ctime).to.be.at.least(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.be.at.least(stats1.atime);
done();
});
});
});
});
});
});
});

File diff suppressed because it is too large Load Diff