added more tests and added spec file to test manifest

This commit is contained in:
Barry Tulchinsky 2013-12-21 16:30:40 -05:00
parent 37d998fb55
commit 55c08e6f08
3 changed files with 217 additions and 13 deletions

View File

@ -27,6 +27,7 @@ define(function(require) {
var EIO = require('src/error').EIO; var EIO = require('src/error').EIO;
var ELoop = require('src/error').ELoop; var ELoop = require('src/error').ELoop;
var EFileSystemError = require('src/error').EFileSystemError; var EFileSystemError = require('src/error').EFileSystemError;
var ENoAttr = require('src/error').ENoAttr;
var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME;
var FS_FORMAT = require('src/constants').FS_FORMAT; var FS_FORMAT = require('src/constants').FS_FORMAT;
@ -1127,14 +1128,14 @@ define(function(require) {
if (error) { if (error) {
callback (error); callback (error);
} }
else if (flag === XATTR_CREATE && node[name]) { else if (flag === XATTR_CREATE && node.xattrs[name]) {
callback(new EExists('attribute already exists')); callback(new EExists('attribute already exists'));
} }
else if (flag === XATTR_REPLACE && !node[name]) { else if (flag === XATTR_REPLACE && !node.xattrs[name]) {
callback(new ENoAttr('attribute does not exist')); callback(new ENoAttr('attribute does not exist'));
} }
else { else {
node.xattr[name] = value; node.xattrs[name] = value;
context.put(node.id, node, callback); context.put(node.id, node, callback);
} }
} }
@ -1163,11 +1164,11 @@ define(function(require) {
if (error) { if (error) {
callback (error); callback (error);
} }
else if (!node.xattr[name]) { else if (!node.xattrs[name]) {
callback(new ENoAttr('attribute does not exist')); callback(new ENoAttr('attribute does not exist'));
} }
else { else {
callback(null, node.xattr[name]); callback(null, node.xattrs[name]);
} }
} }
@ -1622,7 +1623,7 @@ define(function(require) {
} }
}; };
setxattr_file (context, path, name, value, flags, check_result); setxattr_file(context, path, name, value, flag, check_result);
} }
function _lseek(fs, context, fd, offset, whence, callback) { function _lseek(fs, context, fd, offset, whence, callback) {
@ -2087,14 +2088,16 @@ define(function(require) {
); );
}; };
FileSystem.prototype.setxattr = function (path, name, value, flag, callback) { FileSystem.prototype.setxattr = function (path, name, value, flag, callback) {
callback = maybeCallback(arguments[arguments.length - 1]); var callback = maybeCallback(arguments[arguments.length - 1]);
var _flag = (typeof flag != 'function') ? flag : null;
var fs = this; var fs = this;
var error = fs.queueOrRun( var error = fs.queueOrRun(
function () { function () {
var context = fs.provider.getReadWriteContext(); var context = fs.provider.getReadWriteContext();
_setxattr(context, path, name, value, flag, callback); _setxattr(context, path, name, value, _flag, callback);
} }
); );
if (error) { if (error) {
callback(error); callback(error);
} }
@ -2108,6 +2111,7 @@ define(function(require) {
_getxattr(context, path, name, callback); _getxattr(context, path, name, callback);
} }
); );
if (error) { if (error) {
callback(error); callback(error);
} }

View File

@ -1,6 +1,6 @@
define(["IDBFS"], function(IDBFS) { define(["IDBFS"], function(IDBFS) {
describe('fs.utimes', function() { describe('fs.xattr', function() {
beforeEach(function() { beforeEach(function() {
this.db_name = mk_db_name(); this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({ this.fs = new IDBFS.FileSystem({
@ -13,9 +13,208 @@ define(["IDBFS"], function(IDBFS) {
indexedDB.deleteDatabase(this.db_name); indexedDB.deleteDatabase(this.db_name);
delete this.fs; delete this.fs;
}); });
});
it('should be a function', function () { it('should be a function', function () {
expect(typeof this.setxattr).toEqual('function'); expect(typeof this.fs.setxattr).toEqual('function');
expect(typeof this.fs.getxattr).toEqual('function');
}); });
}
it('should error when setting with a name that is not a string', function () {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 89, 'testvalue', function (error) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
it('should error when setting with a name that is null', function () {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', null, 'testvalue', function (error) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
it('should error when setting with a falsy value', function () {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 'test', '', function (error) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
it('should error when setting with an invalid flag', function () {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function (error) {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 'test', 'value', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function (error) {
_error = error;
complete = true;
});
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EExists');
});
});
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function (error) {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function (error) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('ENoAttr');
});
});
it ('should error when getting an attribute with a falsy name', function (error) {
var complete = false;
var _error;
var that = this;
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
that.fs.getxattr('/testfile', '', function (error, value) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
it('should error when getting an attribute when a name is not a string', function (error) {
var complete = false;
var _error;
// var that = this;
var fs = this.fs;
fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
fs.getxattr('/testfile', 89, function (error, value) {
_error = error;
complete = true;
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_error.name).toEqual('EInvalid');
});
});
});
});

View File

@ -28,6 +28,7 @@ define([
"spec/fs.readlink.spec", "spec/fs.readlink.spec",
"spec/fs.truncate.spec", "spec/fs.truncate.spec",
"spec/fs.utimes.spec", "spec/fs.utimes.spec",
"spec/fs.xattr.spec",
"spec/path-resolution.spec", "spec/path-resolution.spec",
// IDBFS.FileSystem.providers.* // IDBFS.FileSystem.providers.*