(function() {
'use strict';
/* global describe, it */
var DIR = __dirname + '/../../',
LIBDIR = DIR + 'lib/',
TMPLDIR = DIR + 'tmpl/',
Util = require(LIBDIR + 'util'),
CloudFunc = require(LIBDIR + 'cloudfunc'),
files = require('files-io'),
rendy = require('rendy'),
FS_DIR = TMPLDIR + 'fs/',
EXPECT_PATH = DIR + 'test/lib/cloudfunc.html',
TMPL_PATH = [
'file',
'path',
'pathLink',
'link',
],
JSON_FILES = {
path : '/etc/X11/',
files : [{
name: 'applnk',
size: 'dir',
uid : 0,
mode: 'rwx r-x r-x'
}, {
name: 'prefdm',
size: '1.30kb',
uid : 0,
mode: 'rwx r-x r-x'
}]
},
Expect =
'
' +
'
' +
'' +
'
' +
'
' +
'/' +
'' +
'etc' +
'/X11/' +
'' +
'
';
describe('cloudfunc', function() {
it('should check', function() {
check();
});
});
function check() {
var paths = {},
filesList = TMPL_PATH.map(function(name) {
var path = FS_DIR + name + '.hbs';
paths[path] = name;
return path;
})
.concat(EXPECT_PATH);
files.read(filesList, 'utf8', function(error, files) {
var isNotOk, expect, result,
i = 0,
template = {};
if (error) {
throw(new Error(error));
} else {
Util.time('CloudFunc.buildFromJSON');
Object.keys(files).forEach(function(path) {
var name = paths[path];
if (path !== EXPECT_PATH)
template[name] = files[path];
});
expect = files[EXPECT_PATH];
result = CloudFunc.buildFromJSON({
prefix : '',
data : JSON_FILES,
template: template
});
Expect += expect;
isNotOk = Expect.split('').some(function(item, number) {
var ret = result[number] !== item;
if (ret)
i = number;
return ret;
});
Util.timeEnd('CloudFunc.buildFromJSON');
if (isNotOk) {
console.log(rendy([
'Error in char number: {{ number }}',
'Expect: {{ expect }}',
'Result: {{ result }}'
].join('\n'), {
number: i,
expect: Expect.substr(i),
result: result.substr(i)
}));
throw('buildFromJSON: Not OK');
}
}
});
}
})();