filer/tests/spec/time-flags.spec.js

107 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

var Filer = require('../../src');
2014-05-23 20:53:50 +00:00
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
2014-05-23 20:53:50 +00:00
describe('node times (atime, mtime, ctime) with mount flags', function() {
var dirname = '/dir';
var filename = '/dir/file';
2014-05-23 20:53:50 +00:00
function memoryFS(flags, callback) {
var name = util.uniqueName();
2018-07-26 21:39:19 +00:00
return new Filer.FileSystem({
2014-05-23 20:53:50 +00:00
name: name,
flags: flags || [],
provider: new Filer.FileSystem.providers.Memory(name)
}, callback);
}
2014-05-23 20:53:50 +00:00
function createTree(fs, callback) {
fs.mkdir(dirname, function(error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.open(filename, 'w', function(error, fd) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.close(fd, callback);
});
2014-05-23 20:53:50 +00:00
});
}
2014-05-23 20:53:50 +00:00
function stat(fs, path, callback) {
fs.stat(path, function(error, stats) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
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.ctimeMs).to.equal(stats1.ctimeMs);
expect(stats2.mtimeMs).to.equal(stats1.mtimeMs);
expect(stats2.atimeMs).to.equal(stats1.atimeMs);
2014-05-23 20:53:50 +00:00
done();
});
});
});
});
});
2014-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
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) {
2014-05-23 20:53:50 +00:00
fs.truncate(filename, 5, function(error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
stat(fs, filename, function(stats2) {
expect(stats2.ctimeMs).to.equal(stats1.ctimeMs);
expect(stats2.mtimeMs).to.equal(stats1.mtimeMs);
expect(stats2.atimeMs).to.equal(stats1.atimeMs);
2014-05-23 20:53:50 +00:00
done();
});
});
});
});
});
2014-05-23 20:53:50 +00:00
});
2014-05-23 20:53:50 +00:00
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) {
2014-05-23 20:53:50 +00:00
fs.truncate(filename, 5, function(error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
stat(fs, filename, function(stats2) {
expect(stats2.ctimeMs).to.be.at.least(stats1.ctimeMs);
expect(stats2.mtimeMs).to.equal(stats1.mtimeMs);
expect(stats2.atimeMs).to.be.at.least(stats1.atimeMs);
2014-05-23 20:53:50 +00:00
done();
});
});
});
});
});
});
});