1 | 'use strict';
|
2 |
|
3 | var _promise = require('babel-runtime/core-js/promise');
|
4 |
|
5 | var _promise2 = _interopRequireDefault(_promise);
|
6 |
|
7 | var _regenerator = require('babel-runtime/regenerator');
|
8 |
|
9 | var _regenerator2 = _interopRequireDefault(_regenerator);
|
10 |
|
11 | var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
12 |
|
13 | var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
14 |
|
15 | var _chai = require('chai');
|
16 |
|
17 | var _mocha = require('mocha');
|
18 |
|
19 | var _childProcessPromise = require('child-process-promise');
|
20 |
|
21 | var _fsPromise = require('fs-promise');
|
22 |
|
23 | var _vmdkRead = require('./vmdk-read');
|
24 |
|
25 | var _vhdWrite = require('./vhd-write');
|
26 |
|
27 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
28 |
|
29 | (0, _mocha.describe)('VMDK to VHD conversion', function () {
|
30 | (0, _mocha.it)('can convert a random data file with readRawContent()', (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
|
31 | var inputRawFileName, vmdkFileName, vhdFileName, reconvertedRawFilemane, dataSize, rawContent, f;
|
32 | return _regenerator2.default.wrap(function _callee$(_context) {
|
33 | while (1) {
|
34 | switch (_context.prev = _context.next) {
|
35 | case 0:
|
36 | inputRawFileName = 'random-data.raw';
|
37 | vmdkFileName = 'random-data.vmdk';
|
38 | vhdFileName = 'from-vmdk-readRawContent.vhd';
|
39 | reconvertedRawFilemane = 'from-vhd.raw';
|
40 | dataSize = 5222400;
|
41 | _context.next = 7;
|
42 | return (0, _childProcessPromise.exec)('rm -f ' + [inputRawFileName, vmdkFileName, vhdFileName, reconvertedRawFilemane].join(' '));
|
43 |
|
44 | case 7:
|
45 | _context.next = 9;
|
46 | return (0, _childProcessPromise.exec)('base64 /dev/urandom | head -c ' + dataSize + ' > ' + inputRawFileName);
|
47 |
|
48 | case 9:
|
49 | _context.next = 11;
|
50 | return (0, _childProcessPromise.exec)('VBoxManage convertfromraw --format VMDK --variant Stream ' + inputRawFileName + ' ' + vmdkFileName);
|
51 |
|
52 | case 11:
|
53 | _context.next = 13;
|
54 | return (0, _vmdkRead.readRawContent)((0, _fsPromise.createReadStream)(vmdkFileName));
|
55 |
|
56 | case 13:
|
57 | rawContent = _context.sent.rawFile;
|
58 | f = new _vhdWrite.VHDFile(rawContent.length, 523557791);
|
59 | _context.next = 17;
|
60 | return f.writeBuffer(rawContent);
|
61 |
|
62 | case 17:
|
63 | _context.next = 19;
|
64 | return f.writeFile(vhdFileName);
|
65 |
|
66 | case 19:
|
67 | _context.next = 21;
|
68 | return (0, _childProcessPromise.exec)('qemu-img convert -fvpc -Oraw ' + vhdFileName + ' ' + reconvertedRawFilemane);
|
69 |
|
70 | case 21:
|
71 | _context.next = 23;
|
72 | return (0, _childProcessPromise.exec)('qemu-img compare ' + vmdkFileName + ' ' + vhdFileName).catch(function (error) {
|
73 | console.error(error.stdout);
|
74 | console.error(error.stderr);
|
75 | _chai.assert.fail(vhdFileName, vmdkFileName, error.message);
|
76 | });
|
77 |
|
78 | case 23:
|
79 | case 'end':
|
80 | return _context.stop();
|
81 | }
|
82 | }
|
83 | }, _callee, undefined);
|
84 | })));
|
85 | (0, _mocha.it)('can convert a random data file with VMDKDirectParser', (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() {
|
86 | var inputRawFileName, vmdkFileName, vhdFileName, reconvertedRawFilemane, reconvertedByVBoxRawFilemane, dataSize, pipe;
|
87 | return _regenerator2.default.wrap(function _callee2$(_context2) {
|
88 | while (1) {
|
89 | switch (_context2.prev = _context2.next) {
|
90 | case 0:
|
91 | inputRawFileName = 'random-data.raw';
|
92 | vmdkFileName = 'random-data.vmdk';
|
93 | vhdFileName = 'from-vmdk-VMDKDirectParser.vhd';
|
94 | reconvertedRawFilemane = 'from-vhd.raw';
|
95 | reconvertedByVBoxRawFilemane = 'from-vhd-by-vbox.raw';
|
96 | dataSize = (0, _vhdWrite.computeGeometryForSize)(8 * 1024 * 1024).actualSize;
|
97 | _context2.next = 8;
|
98 | return (0, _childProcessPromise.exec)('rm -f ' + [inputRawFileName, vmdkFileName, vhdFileName, reconvertedRawFilemane, reconvertedByVBoxRawFilemane].join(' '));
|
99 |
|
100 | case 8:
|
101 | _context2.next = 10;
|
102 | return (0, _childProcessPromise.exec)('base64 /dev/urandom | head -c ' + dataSize + ' > ' + inputRawFileName);
|
103 |
|
104 | case 10:
|
105 | console.log('after urandom');
|
106 |
|
107 | _context2.next = 13;
|
108 | return (0, _childProcessPromise.exec)('VBoxManage convertfromraw --format VMDK --variant Stream ' + inputRawFileName + ' ' + vmdkFileName);
|
109 |
|
110 | case 13:
|
111 |
|
112 | console.log('after convertfromraw');
|
113 | _context2.next = 16;
|
114 | return (0, _vhdWrite.convertFromVMDK)((0, _fsPromise.createReadStream)(vmdkFileName));
|
115 |
|
116 | case 16:
|
117 | _context2.t0 = (0, _fsPromise.createWriteStream)(vhdFileName);
|
118 | pipe = _context2.sent.pipe(_context2.t0);
|
119 | _context2.next = 20;
|
120 | return new _promise2.default(function (resolve, reject) {
|
121 | pipe.on('finish', resolve);
|
122 | pipe.on('error', reject);
|
123 | });
|
124 |
|
125 | case 20:
|
126 | console.log('after pipe');
|
127 | _context2.next = 23;
|
128 | return (0, _childProcessPromise.exec)('qemu-img convert -fvmdk -Oraw ' + vmdkFileName + ' ' + reconvertedByVBoxRawFilemane);
|
129 |
|
130 | case 23:
|
131 | console.log('after convert1');
|
132 | _context2.next = 26;
|
133 | return (0, _childProcessPromise.exec)('qemu-img convert -fvpc -Oraw ' + vhdFileName + ' ' + reconvertedRawFilemane);
|
134 |
|
135 | case 26:
|
136 | console.log('after convert2');
|
137 | return _context2.abrupt('return', (0, _childProcessPromise.exec)('qemu-img compare ' + reconvertedByVBoxRawFilemane + ' ' + reconvertedRawFilemane).catch(function (error) {
|
138 | console.error(error.stdout);
|
139 | console.error(error.stderr);
|
140 | _chai.assert.fail(vhdFileName, vmdkFileName, error.message);
|
141 | }));
|
142 |
|
143 | case 28:
|
144 | case 'end':
|
145 | return _context2.stop();
|
146 | }
|
147 | }
|
148 | }, _callee2, undefined);
|
149 | })));
|
150 | });
|
151 |
|
\ | No newline at end of file |