Add tests for time mount flag suppression (NOMTIME, NOCTIME)

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-03-05 21:41:45 -05:00
parent 5438d8c97b
commit 72e527dfab
2 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,106 @@
define(["Filer", "util"], function(Filer, util) {
describe('node times (atime, mtime, ctime) with mount flags', function() {
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 createTree(fs, callback) {
fs.mkdir(dirname, function(error) {
if(error) throw error;
fs.open(filename, 'w', function(error, fd) {
if(error) throw error;
fs.close(fd, callback);
});
});
}
function stat(fs, path, callback) {
fs.stat(path, function(error, stats) {
if(error) throw error;
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.
*/
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) {
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();
});
});
});
});
});
});
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;
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) {
fs.truncate(filename, 5, function(error) {
if(error) throw error;
stat(fs, filename, function(stats2) {
expect(stats2.ctime).to.be.above(stats1.ctime);
expect(stats2.mtime).to.equal(stats1.mtime);
expect(stats2.atime).to.be.above(stats1.atime);
done();
});
});
});
});
});
});
});
});

View File

@ -33,6 +33,7 @@ define([
"spec/fs.xattr.spec", "spec/fs.xattr.spec",
"spec/path-resolution.spec", "spec/path-resolution.spec",
"spec/times.spec", "spec/times.spec",
"spec/time-flags.spec",
// Filer.FileSystem.providers.* // Filer.FileSystem.providers.*
"spec/providers/providers.spec", "spec/providers/providers.spec",