fix(xo-vmdk-to-vhd): remove depency to xmllint for source users (#6195)

This commit is contained in:
Florent BEAUCHAMP 2022-04-20 16:07:28 +02:00 committed by GitHub
parent 1646c50a94
commit 95ec5929b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -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/",

View File

@ -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])