2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
describe('fs.open', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.open).to.be.a('function');
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return an error if the parent path does not exist', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/tmp/myfile', 'w+', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return an error when flagged for read and the path does not exist', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'r+', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return an error when flagged for write and the path is a directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.mkdir('/tmp', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/tmp', 'w', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return an error when flagged for append and the path is a directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.mkdir('/tmp', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/tmp', 'a', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return a unique file descriptor', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var fd1
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/file1', 'w+', function(error, fd) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
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();
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should create a new file when flagged for write', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result.type).to.equal('FILE');
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
});
|