Skip to content

Commit

Permalink
Add Unit tests for filecache
Browse files Browse the repository at this point in the history
  • Loading branch information
pboyd04 committed Nov 22, 2016
1 parent b7b9cd3 commit 8203600
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/filecache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const FileCache = require('../lib/cache/fileCache');

module.exports.construct = function(assert) {
var fc = new FileCache();
assert.equal(fc.localDirs, null);
assert.equal(fc.useNetwork, true);

fc = new FileCache('test');
assert.equal(fc.localDirs, 'test');
assert.equal(fc.useNetwork, true);

fc = new FileCache(['test', 'test2']);
assert.deepEqual(fc.localDirs, ['test', 'test2']);
assert.equal(fc.useNetwork, true);

fc = new FileCache(['test', 'test2'], true);
assert.deepEqual(fc.localDirs, ['test', 'test2']);
assert.equal(fc.useNetwork, true);

fc = new FileCache(['test', 'test2'], false);
assert.deepEqual(fc.localDirs, ['test', 'test2']);
assert.equal(fc.useNetwork, false);

fc = new FileCache(null, true);
assert.equal(fc.localDirs, null);
assert.equal(fc.useNetwork, true);

assert.done();
}

module.exports.hasFile = function(assert) {
var fc = new FileCache([__dirname + '/fixtures/'], false);
assert.equal(fc.hasFile('http://example.com/SimpleMetadata.xml'), false);
var promise = fc.getFile('http://example.com/SimpleMetadata.xml');
promise.then(function(data) {
assert.notEqual(data, undefined);
assert.equal(fc.hasFile('http://example.com/SimpleMetadata.xml'), true);
}). catch(function(err) {
throw err;
});

assert.done();
}
/* vim: set tabstop=2 shiftwidth=2 expandtab: */

0 comments on commit 8203600

Please sign in to comment.