Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     'use strict';
  3.     var plugin = window.kontur.plugin;
  4.     var tests = plugin.tests;
  5.     var Promise = window.ES6Promise.Promise;
  6.    
  7.     function assert (expected) {
  8.         return tests.send({
  9.             type: 'hash.md5',
  10.             source: {
  11.                 type: 'file',
  12.                 path: tests.getSampleFile('drive')
  13.             },
  14.             sink: {type: 'hex'}
  15.             }).then(function(result) {
  16.                 expect(result.type).to.equal('hex');
  17.                 expect(result.data).to.equal(expected);
  18.                 });
  19.         }
  20.  
  21.     function funcDrive2(options) {
  22.         return new Promise(function(resolve) {
  23.        
  24.         var countValue = Math.floor(options.size / options.pieces);
  25.         var sourceOffsetValues = Array();
  26.         var mode;
  27.         for (var i = 0; i <= options.pieces; i++) {
  28.             sourceOffsetValues.push(i * countValue);
  29.         }
  30.         sourceOffsetValues.reduce(function(promise, sourceOffsetValue) {
  31.    
  32.                 return promise.then(function() {
  33.                     return tests.send({
  34.                         type: 'io.transfer',
  35.                         source: options.testData,
  36.                         sink: options.sink,
  37.                         sourceOffset: sourceOffsetValue,
  38.                         count: countValue
  39.                     });
  40.                     }).then(function(result) {
  41.                     return tests.send({
  42.                         type: 'archive.gzip',
  43.                         source: result,
  44.                         sink: options.secondsink
  45.                     });
  46.                 }).then(function(result) {
  47.                     return tests.send({
  48.                         type: 'archive.ungzip',
  49.                         source: result,
  50.                         sink: options.sink
  51.                     });
  52.                 }).then(function(result) {
  53.                     if (sourceOffsetValue === 0) {
  54.                         mode = 'create';
  55.                     } else {
  56.                         mode = 'open';
  57.                     }
  58.                     return tests.send({
  59.                         type: 'io.transfer',
  60.                         source: result,
  61.                         sink: {
  62.                             type: 'file',
  63.                             path: tests.getSampleFile('drive'),
  64.                             mode: mode,
  65.                             access: 'readWrite'
  66.                         },
  67.                         sinkOffset: sourceOffsetValue
  68.                     });
  69.                 }).then(function(result){
  70.                     resolve(result);
  71.                 });
  72.                  
  73.             }, Promise.resolve());
  74.     });
  75.  
  76. }
  77.      
  78.  
  79.             describe('Drive', function() {
  80.  
  81.               it('Drive with small file, 2 pieces (base64)', function() {
  82.                    
  83.                     funcDrive2({
  84.                         testData: {
  85.                             type: 'file',
  86.                             path: tests.getSampleFile('medium')
  87.                         },
  88.                         sink: {
  89.                             type: 'base64'
  90.                         },
  91.                         secondsink: {
  92.                             type: 'base64'
  93.                         },
  94.                         mode: 'openOrCreate',
  95.                         size: 1481643 ,
  96.                         pieces: 2
  97.                     }).then(function() {
  98.                         setTimeout(function() {
  99.                               assert('a39827b88fb33a4074f310625560bc86');
  100.                     }, 10000);
  101.                     });
  102.        
  103.          
  104.             });
  105.    
  106.             });
  107. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement