Skip to content

Commit

Permalink
fix(xo-vmdk-to-vhd): remove depency to xmllint for source users (#6195)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Apr 20, 2022
1 parent 1646c50 commit 95ec592
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/xo-vmdk-to-vhd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
38 changes: 36 additions & 2 deletions packages/xo-vmdk-to-vhd/src/ova-generate.integ.spec.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 95ec592

Please sign in to comment.