fix(xo-vmdk-to-vhd): remove depency to xmllint for source users (#6195)
This commit is contained in:
parent
1646c50a94
commit
95ec5929b4
@ -40,8 +40,7 @@
|
|||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"get-stream": "^6.0.0",
|
"get-stream": "^6.0.0",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "^3.0.0",
|
||||||
"tmp": "^0.2.1",
|
"tmp": "^0.2.1"
|
||||||
"validate-with-xmllint": "^1.2.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* eslint-env jest */
|
/* eslint-env jest */
|
||||||
import { validateXMLWithXSD } from 'validate-with-xmllint'
|
import { spawn } from 'child_process'
|
||||||
import { createReadStream, createWriteStream, readFile } from 'fs-extra'
|
import { createReadStream, createWriteStream, readFile } from 'fs-extra'
|
||||||
import execa from 'execa'
|
import execa from 'execa'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
@ -21,6 +21,34 @@ afterEach(async () => {
|
|||||||
process.chdir(initialDir)
|
process.chdir(initialDir)
|
||||||
await pFromCallback(cb => rimraf(tmpDir, cb))
|
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 () => {
|
test('An ova file is generated correctly', async () => {
|
||||||
const inputRawFileName1 = 'random-data1.raw'
|
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' })
|
const xml = await readFile('vm1.ovf', { encoding: 'utf-8' })
|
||||||
|
|
||||||
try {
|
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, vmdkDiskName1])
|
||||||
await execa('tar', ['xf', ovaFileName1, vmdkDiskName2])
|
await execa('tar', ['xf', ovaFileName1, vmdkDiskName2])
|
||||||
await execa('qemu-img', ['check', vmdkDiskName1])
|
await execa('qemu-img', ['check', vmdkDiskName1])
|
||||||
|
Loading…
Reference in New Issue
Block a user