diff --git a/packages/xo-vmdk-to-vhd/package.json b/packages/xo-vmdk-to-vhd/package.json index 4123c858d..09257e670 100644 --- a/packages/xo-vmdk-to-vhd/package.json +++ b/packages/xo-vmdk-to-vhd/package.json @@ -40,8 +40,7 @@ "fs-extra": "^10.0.0", "get-stream": "^6.0.0", "rimraf": "^3.0.0", - "tmp": "^0.2.1", - "validate-with-xmllint": "^1.2.0" + "tmp": "^0.2.1" }, "scripts": { "build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/", diff --git a/packages/xo-vmdk-to-vhd/src/ova-generate.integ.spec.js b/packages/xo-vmdk-to-vhd/src/ova-generate.integ.spec.js index 10702db91..a1e09ae81 100644 --- a/packages/xo-vmdk-to-vhd/src/ova-generate.integ.spec.js +++ b/packages/xo-vmdk-to-vhd/src/ova-generate.integ.spec.js @@ -1,5 +1,5 @@ /* eslint-env jest */ -import { validateXMLWithXSD } from 'validate-with-xmllint' +import { spawn } from 'child_process' import { createReadStream, createWriteStream, readFile } from 'fs-extra' import execa from 'execa' import path from 'path' @@ -21,6 +21,34 @@ afterEach(async () => { process.chdir(initialDir) await pFromCallback(cb => rimraf(tmpDir, cb)) }) +// from https://github.com/aautio/validate-with-xmllint/blob/master/src/index.ts +// that way the test will fail if user does not have xml-lint installed on its os +// but the XO install will succeed + +const execXmllint = (input, args) => + new Promise((resolve, reject) => { + const xmllint = spawn('xmllint', args) + + // stdout and stderr are both captured to be made available if the promise rejects + let output = '' + xmllint.stdout.on('data', chunk => (output += chunk.toString())) + xmllint.stderr.on('data', chunk => (output += chunk.toString())) + + // Any errors cause a rejection + xmllint.on('error', reject) + + xmllint.on('close', code => { + if (code === 0) { + return resolve() + } + return reject( + new Error(`xmllint exited with code ${code} when executed with xmllint ${args.join(' ')}:\n${output}`) + ) + }) + + // pipe input to process + xmllint.stdin.end(input) + }) test('An ova file is generated correctly', async () => { const inputRawFileName1 = 'random-data1.raw' @@ -69,7 +97,13 @@ test('An ova file is generated correctly', async () => { const xml = await readFile('vm1.ovf', { encoding: 'utf-8' }) try { - await validateXMLWithXSD(xml, path.join(__dirname, 'ova-schema', 'dsp8023_1.1.1.xsd')) + await execXmllint(xml, [ + '--schema', + path.join(__dirname, 'ova-schema', 'dsp8023_1.1.1.xsd'), + '--noout', + '--nonet', + '-', + ]) await execa('tar', ['xf', ovaFileName1, vmdkDiskName1]) await execa('tar', ['xf', ovaFileName1, vmdkDiskName2]) await execa('qemu-img', ['check', vmdkDiskName1])