diff --git a/test/expect.html b/test/expect.html new file mode 100644 index 00000000..49b3f67f --- /dev/null +++ b/test/expect.html @@ -0,0 +1,22 @@ +
  • + + + .. + + <dir>. + +
  • + + + applnk + + <dir>root + rwx r-x r-x +
  • + + + prefdm + + 1.30kbroot + rwx r-x r-x +
  • \ No newline at end of file diff --git a/test/test.js b/test/test.js index fd131686..2ead67a1 100644 --- a/test/test.js +++ b/test/test.js @@ -1,10 +1,19 @@ (function(){ 'use strict'; - var DIR = process.cwd() + '/', - main = require(DIR + 'lib/server/main'), + var DIR = process.cwd() + '/', + main = require(DIR + 'lib/server/main'), + + Util = main.util, - CloudFunc = main.cloudfunc, + CloudFunc = main.cloudfunc, + HTMLDIR = main.HTMLDIR, + + TEMPLATEPATH = HTMLDIR + 'file.html', + PATHTEMPLATE_PATH = HTMLDIR + 'path.html', + EXPECT_PATH = DIR + 'test/expect.html', + + Files = [TEMPLATEPATH, PATHTEMPLATE_PATH, EXPECT_PATH], lJSON = [{ "path": "/etc/X11/", @@ -19,80 +28,59 @@ "size": 1328, "uid": 0, "mode": "100755" - }]; - - start(); - var lResult = CloudFunc.buildFromJSON(lJSON); - end(); - - var lExpect = - '
  • ' + - '' + - '' + - ''+ - '' + - '' + - '/' + - '' + - 'etc' + - '/X11/' + - '' + - '
  • ' + - '
  • ' + - '' + - 'name' + - 'size' + - 'owner' + - 'mode' + - '
  • ' + - '
  • ' + - '' + - '' + - '..' + - '' + - '<dir>' + - '.' + - '' + - '
  • ' + - '
  • ' + - '' + - '' + - 'applnk' + - '' + - '<dir>' + - 'root' + - 'rwx r-x r-x' + - '
  • ' + - '
  • ' + - '' + - '' + - '' + - 'prefdm' + - '' + - '' + - '1.30kb' + - 'root' + - 'rwx r-x r-x' + - '
  • '; + }], - for(var i = 0, n = lExpect.length; i < n; i++) - if(lResult[i] !== lExpect[i]){ - console.log('Error in char number: ' + i + '\n' + - 'Expect: ' + lExpect.substr(i) + '\n' + - 'Result: ' + lResult.substr(i) ); - break; + + Expect = + '
  • ' + + '' + + '' + + ''+ + '' + + '' + + '/' + + '' + + 'etc' + + '/X11/' + + '' + + '
  • ' + + '
  • ' + + '' + + 'name' + + 'size' + + 'owner' + + 'mode' + + '
  • '; + + + main.readFiles(Files, function(pErrors, pFiles){ + if(pErrors) + Util.log(pErrors); + else{ + console.time('CloudFunc.buildFromJSON'); + + var lTemplate = pFiles[TEMPLATEPATH].toString(), + lPathTemplate = pFiles[PATHTEMPLATE_PATH].toString(), + lExpect = pFiles[EXPECT_PATH].toString(), + + lResult = CloudFunc.buildFromJSON(lJSON, lTemplate, lPathTemplate); + + Expect += lExpect; + + for(var i = 0, n = Expect.length; i < n; i++) + if(lResult[i] !== Expect[i]){ + console.log('Error in char number: ' + i + '\n' + + 'Expect: ' + Expect.substr(i) + '\n' + + 'Result: ' + lResult.substr(i) ); + break; + } + + if(i===n) + console.log('CloudFunc.buildFromJSON: OK'); + + console.timeEnd('CloudFunc.buildFromJSON'); } - if(i===n) - console.log('CloudFunc.buildFromJSON: OK'); - - - function start(){ - return console.time('CloudFunc.buildFromJSON'); - } - function end(){ - return console.timeEnd('CloudFunc.buildFromJSON'); - } + }); + })();