Compare commits

...

2 Commits

Author SHA1 Message Date
ggunullu
715ab283e4 change path to schema repo 2023-05-17 15:48:05 +02:00
ggunullu
f9a65e244c test(xo-vmdk-to-vhd): from Jest to test 2023-05-16 21:01:03 +02:00
6 changed files with 35 additions and 20 deletions

View File

@@ -39,6 +39,8 @@
"fs-extra": "^11.1.1",
"get-stream": "^6.0.0",
"rimraf": "^4.1.1",
"sinon": "^15.0.4",
"test": "^3.3.0",
"tmp": "^0.2.1"
},
"scripts": {
@@ -48,7 +50,9 @@
"prebuild": "yarn run clean",
"predev": "yarn run clean",
"prepublishOnly": "yarn run build",
"postversion": "npm publish"
"pretest-integration": "yarn run build",
"postversion": "npm publish",
"test-integration": "node--test ./dist/*.integ.js"
},
"author": {
"name": "Vates SAS",

View File

@@ -1,4 +1,6 @@
/* eslint-env jest */
import { afterEach, beforeEach, test } from 'test'
import sinon from 'sinon'
import { spawn } from 'child_process'
import { createReadStream, createWriteStream, readFile } from 'fs-extra'
import execa from 'execa'
@@ -10,7 +12,8 @@ import { writeOvaOn } from './ova-generate'
import { parseOVF } from './ova-read'
const initialDir = process.cwd()
jest.setTimeout(100000)
const clock = sinon.useFakeTimers()
clock.tick(100000)
beforeEach(async () => {
const dir = await pFromCallback(cb => tmp.dir(cb))
process.chdir(dir)
@@ -99,7 +102,7 @@ test('An ova file is generated correctly', async () => {
try {
await execXmllint(xml, [
'--schema',
path.join(__dirname, 'ova-schema', 'dsp8023_1.1.1.xsd'),
path.join(__dirname, '../src/ova-schema', 'dsp8023_1.1.1.xsd'),
'--noout',
'--nonet',
'-',

View File

@@ -1,4 +1,5 @@
/* eslint-env jest */
import { afterEach, beforeEach, test } from 'test'
import { strict as assert } from 'assert'
import { exec } from 'child-process-promise'
import { createReadStream } from 'fs'
@@ -66,14 +67,14 @@ test('An ova file is parsed correctly', async () => {
const directGrainTableFetch = await readVmdkGrainTable(async (start, end) =>
vmdkParsableFile.slice(start, end).read()
)
expect(directGrainTableFetch).toEqual(expectedResult.tables[vmdkFileName])
assert.deepEqual(directGrainTableFetch, expectedResult.tables[vmdkFileName])
const data = await parseOVAFile(new NodeParsableFile(ovaName), (buffer, encoder) => {
return Buffer.from(buffer).toString(encoder)
})
for (const fileName in data.tables) {
data.tables[fileName] = await data.tables[fileName]
}
expect(data).toEqual(expectedResult)
assert.deepEqual(data, expectedResult)
})
function arrayToBuffer(array) {

View File

@@ -1,4 +1,5 @@
/* eslint-env jest */
import { afterEach, beforeEach, test } from 'test'
import { strict as assert } from 'assert'
import { createReadStream, readFile } from 'fs-extra'
import { exec } from 'child-process-promise'
@@ -28,5 +29,5 @@ test('Virtual Buffer can read a file correctly', async () => {
const part1 = await buffer.readChunk(10)
const part2 = await buffer.readChunk(1038)
const original = await readFile(rawFileName)
expect(Buffer.concat([part1, part2]).toString('ascii')).toEqual(original.toString('ascii'))
assert.equal(Buffer.concat([part1, part2]).toString('ascii'), original.toString('ascii'))
})

View File

@@ -1,4 +1,6 @@
/* eslint-env jest */
import { afterEach, beforeEach, test } from 'test'
import { strict as assert } from 'assert'
import sinon from 'sinon'
import { createReadStream, stat } from 'fs-extra'
import { exec } from 'child-process-promise'
@@ -34,7 +36,8 @@ function bufferToArray(buffer) {
return res
}
jest.setTimeout(10000)
const clock = sinon.useFakeTimers()
clock.tick(10000)
const initialDir = process.cwd()
@@ -67,8 +70,8 @@ test('VMDKDirectParser reads OK', async () => {
for await (const res of parser.blockIterator()) {
harvested.push(res)
}
expect(harvested.length).toEqual(2)
expect(harvested[0].logicalAddressBytes).toEqual(0)
expect(harvested[0].data.length).toEqual(header.grainSizeSectors * 512)
expect(harvested[1].logicalAddressBytes).toEqual(header.grainSizeSectors * 512)
assert.equal(harvested.length, 2)
assert.equal(harvested[0].logicalAddressBytes, 0)
assert.equal(harvested[0].data.length, header.grainSizeSectors * 512)
assert.equal(harvested[1].logicalAddressBytes, header.grainSizeSectors * 512)
})

View File

@@ -1,4 +1,6 @@
/* eslint-env jest */
import { afterEach, beforeEach, test } from 'test'
import { strict as assert } from 'assert'
import sinon from 'sinon'
import execa from 'execa'
import fromEvent from 'promise-toolbox/fromEvent'
@@ -15,7 +17,8 @@ import asyncIteratorToStream from 'async-iterator-to-stream'
import fs from 'fs'
const initialDir = process.cwd()
jest.setTimeout(100000)
const clock = sinon.useFakeTimers()
clock.tick(100000)
beforeEach(async () => {
const dir = await pFromCallback(cb => tmp.dir(cb))
@@ -124,7 +127,7 @@ test('Can generate a small VMDK file', async () => {
}
}
const data = await readVmdkGrainTable(createFileAccessor(fileName))
expect(bufferToArray(data.grainLogicalAddressList)).toEqual(expectedLBAs)
assert.deepEqual(bufferToArray(data.grainLogicalAddressList), expectedLBAs)
const grainFileOffsetList = bufferToArray(data.grainFileOffsetList)
const parser = new VMDKDirectParser(
createReadStream(fileName),
@@ -142,8 +145,8 @@ test('Can generate a small VMDK file', async () => {
}
const resultBuffer = Buffer.concat(resBuffers)
const startingBuffer = Buffer.concat([b1, b2])
expect(resultBuffer).toEqual(startingBuffer)
expect(resLbas).toEqual(expectedLBAs)
assert.deepEqual(resultBuffer, startingBuffer)
assert.deepEqual(resLbas, expectedLBAs)
await execa('qemu-img', ['check', 'result.vmdk'])
})