tests: datalayout
This commit is contained in:
@@ -6,6 +6,7 @@ const assert = require('assert'),
|
||||
class DataLayout {
|
||||
constructor(localRoot, dirMap) {
|
||||
assert.strictEqual(typeof localRoot, 'string');
|
||||
assert(path.isAbsolute(localRoot));
|
||||
assert(Array.isArray(dirMap), 'Expecting layout to be an array');
|
||||
|
||||
this._localRoot = localRoot;
|
||||
@@ -13,6 +14,7 @@ class DataLayout {
|
||||
this._remoteRegexps = dirMap.map((l) => new RegExp('^\\./' + l.remoteDir + '/?'));
|
||||
this._localRegexps = dirMap.map((l) => new RegExp('^' + l.localDir + '/?'));
|
||||
}
|
||||
// returns absolute path
|
||||
toLocalPath(remoteName) {
|
||||
assert.strictEqual(typeof remoteName, 'string');
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const DataLayout = require('../datalayout.js'),
|
||||
expect = require('expect.js');
|
||||
|
||||
describe('DataLayout', function () {
|
||||
describe('no dirMap', function () {
|
||||
const BOX_DATA_DIR = '/home/yellowtent/boxdata/box';
|
||||
const dataLayout = new DataLayout(BOX_DATA_DIR, []);
|
||||
|
||||
it('localRoot', function () {
|
||||
expect(dataLayout.localRoot()).to.be(BOX_DATA_DIR);
|
||||
});
|
||||
|
||||
it('getBasename', function () {
|
||||
expect(dataLayout.getBasename()).to.be('box');
|
||||
});
|
||||
|
||||
it('localPaths', function () {
|
||||
expect(dataLayout.localPaths()).to.eql([ BOX_DATA_DIR ]);
|
||||
});
|
||||
|
||||
it('toLocalPath', function () {
|
||||
expect(dataLayout.toLocalPath('./s1')).to.be(`${BOX_DATA_DIR}/s1`);
|
||||
expect(dataLayout.toLocalPath('./s1/')).to.be(`${BOX_DATA_DIR}/s1/`);
|
||||
expect(dataLayout.toLocalPath('./s1/s2')).to.be(`${BOX_DATA_DIR}/s1/s2`);
|
||||
});
|
||||
|
||||
it('toRemotePath', function () {
|
||||
expect(dataLayout.toRemotePath(`${BOX_DATA_DIR}`)).to.be('./');
|
||||
expect(dataLayout.toRemotePath(`${BOX_DATA_DIR}/s1`)).to.be('./s1');
|
||||
expect(dataLayout.toRemotePath(`${BOX_DATA_DIR}/s1/`)).to.be('./s1/');
|
||||
expect(dataLayout.toRemotePath(`${BOX_DATA_DIR}/s1/s2`)).to.be('./s1/s2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with dirMap', function () {
|
||||
const APP_DATA_DIR = '/home/yellowtent/appsdata/appid';
|
||||
const EXT_DIR = '/srv/hsb';
|
||||
const dataLayout = new DataLayout(APP_DATA_DIR, [ { localDir: EXT_DIR, remoteDir: 'data' }]);
|
||||
|
||||
it('localRoot', function () {
|
||||
expect(dataLayout.localRoot()).to.be(APP_DATA_DIR);
|
||||
});
|
||||
|
||||
it('getBasename', function () {
|
||||
expect(dataLayout.getBasename()).to.be('appid');
|
||||
});
|
||||
|
||||
it('localPaths', function () {
|
||||
expect(dataLayout.localPaths()).to.eql([ APP_DATA_DIR, '/srv/hsb' ]);
|
||||
});
|
||||
|
||||
it('toLocalPath - root', function () {
|
||||
expect(dataLayout.toLocalPath('./s1')).to.be(`${APP_DATA_DIR}/s1`);
|
||||
expect(dataLayout.toLocalPath('./s1/')).to.be(`${APP_DATA_DIR}/s1/`);
|
||||
expect(dataLayout.toLocalPath('./s1/s2')).to.be(`${APP_DATA_DIR}/s1/s2`);
|
||||
});
|
||||
|
||||
it('toLocalPath - extdir', function () {
|
||||
expect(dataLayout.toLocalPath('./data/s1')).to.be(`${EXT_DIR}/s1`);
|
||||
expect(dataLayout.toLocalPath('./data/s1/')).to.be(`${EXT_DIR}/s1/`);
|
||||
expect(dataLayout.toLocalPath('./data/s1/s2')).to.be(`${EXT_DIR}/s1/s2`);
|
||||
});
|
||||
|
||||
it('toRemotePath - root', function () {
|
||||
expect(dataLayout.toRemotePath(`${APP_DATA_DIR}`)).to.be('./');
|
||||
expect(dataLayout.toRemotePath(`${APP_DATA_DIR}/s1`)).to.be('./s1');
|
||||
expect(dataLayout.toRemotePath(`${APP_DATA_DIR}/s1/`)).to.be('./s1/');
|
||||
expect(dataLayout.toRemotePath(`${APP_DATA_DIR}/s1/s2`)).to.be('./s1/s2');
|
||||
});
|
||||
|
||||
it('toRemotePath - extdir', function () {
|
||||
expect(dataLayout.toRemotePath(`${EXT_DIR}`)).to.be('./data/');
|
||||
expect(dataLayout.toRemotePath(`${EXT_DIR}/s1`)).to.be('./data/s1');
|
||||
expect(dataLayout.toRemotePath(`${EXT_DIR}/s1/`)).to.be('./data/s1/');
|
||||
expect(dataLayout.toRemotePath(`${EXT_DIR}/s1/s2`)).to.be('./data/s1/s2');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user