fix: various VHD related test fixes (#6302)

This commit is contained in:
Florent BEAUCHAMP
2022-08-12 16:23:59 +02:00
committed by GitHub
parent 61691ac46b
commit b89e77a6a4
9 changed files with 76 additions and 50 deletions

View File

@@ -35,7 +35,7 @@ afterEach(async () => {
})
const uniqueId = () => uuid.v1()
const uniqueIdBuffer = () => Buffer.from(uniqueId(), 'utf-8')
const uniqueIdBuffer = () => uuid.v1({}, Buffer.alloc(16))
async function generateVhd(path, opts = {}) {
let vhd
@@ -78,15 +78,15 @@ test('It remove broken vhd', async () => {
await handler.writeFile(`${basePath}/notReallyAVhd.vhd`, 'I AM NOT A VHD')
expect((await handler.list(basePath)).length).toEqual(1)
let loggued = ''
const onLog = message => {
const logInfo = message => {
loggued += message
}
await adapter.cleanVm('/', { remove: false, onLog })
expect(loggued).toEqual(`error while checking the VHD with path /${basePath}/notReallyAVhd.vhd`)
await adapter.cleanVm('/', { remove: false, logInfo, logWarn: logInfo, lock: false })
expect(loggued).toEqual(`VHD check error`)
// not removed
expect((await handler.list(basePath)).length).toEqual(1)
// really remove it
await adapter.cleanVm('/', { remove: true, onLog })
await adapter.cleanVm('/', { remove: true, logInfo, logWarn: () => {}, lock: false })
expect((await handler.list(basePath)).length).toEqual(0)
})
@@ -118,15 +118,13 @@ test('it remove vhd with missing or multiple ancestors', async () => {
)
// clean
let loggued = ''
const onLog = message => {
const logInfo = message => {
loggued += message + '\n'
}
await adapter.cleanVm('/', { remove: true, onLog })
await adapter.cleanVm('/', { remove: true, logInfo, logWarn: logInfo, lock: false })
const deletedOrphanVhd = loggued.match(/deleting orphan VHD/g) || []
expect(deletedOrphanVhd.length).toEqual(1) // only one vhd should have been deleted
const deletedAbandonnedVhd = loggued.match(/abandonned.vhd is missing/g) || []
expect(deletedAbandonnedVhd.length).toEqual(1) // and it must be abandonned.vhd
// we don't test the filew on disk, since they will all be marker as unused and deleted without a metadata.json file
})
@@ -159,14 +157,12 @@ test('it remove backup meta data referencing a missing vhd in delta backup', asy
})
let loggued = ''
const onLog = message => {
const logInfo = message => {
loggued += message + '\n'
}
await adapter.cleanVm('/', { remove: true, onLog })
let matched = loggued.match(/deleting unused VHD /g) || []
await adapter.cleanVm('/', { remove: true, logInfo, logWarn: logInfo , lock: false})
let matched = loggued.match(/deleting unused VHD/g) || []
expect(matched.length).toEqual(1) // only one vhd should have been deleted
matched = loggued.match(/abandonned.vhd is unused/g) || []
expect(matched.length).toEqual(1) // and it must be abandonned.vhd
// a missing vhd cause clean to remove all vhds
await handler.writeFile(
@@ -183,8 +179,8 @@ test('it remove backup meta data referencing a missing vhd in delta backup', asy
{ flags: 'w' }
)
loggued = ''
await adapter.cleanVm('/', { remove: true, onLog })
matched = loggued.match(/deleting unused VHD /g) || []
await adapter.cleanVm('/', { remove: true, logInfo, logWarn: () => {} , lock: false})
matched = loggued.match(/deleting unused VHD/g) || []
expect(matched.length).toEqual(2) // all vhds (orphan and child ) should have been deleted
})
@@ -220,16 +216,16 @@ test('it merges delta of non destroyed chain', async () => {
})
let loggued = []
const onLog = message => {
const logInfo = message => {
loggued.push(message)
}
await adapter.cleanVm('/', { remove: true, onLog })
expect(loggued[0]).toEqual(`incorrect size in metadata: 12000 instead of 209920`)
await adapter.cleanVm('/', { remove: true, logInfo, logWarn: logInfo, lock: false })
expect(loggued[0]).toEqual(`incorrect backup size in metadata`)
loggued = []
await adapter.cleanVm('/', { remove: true, merge: true, onLog })
await adapter.cleanVm('/', { remove: true, merge: true, logInfo, logWarn: () => {}, lock: false })
const [merging] = loggued
expect(merging).toEqual(`merging 1 children into /${basePath}/orphan.vhd`)
expect(merging).toEqual(`merging VHD chain`)
const metadata = JSON.parse(await handler.readFile(`metadata.json`))
// size should be the size of children + grand children after the merge
@@ -275,7 +271,7 @@ test('it finish unterminated merge ', async () => {
})
)
await adapter.cleanVm('/', { remove: true, merge: true })
await adapter.cleanVm('/', { remove: true, merge: true, logWarn: ()=>{}, lock: false})
// merging is already tested in vhd-lib, don't retest it here (and theses vhd are as empty as my stomach at 12h12)
// only check deletion
@@ -382,7 +378,7 @@ describe('tests multiple combination ', () => {
})
)
await adapter.cleanVm('/', { remove: true, merge: true })
await adapter.cleanVm('/', { remove: true, merge: true, logWarn: () => {}, lock: false })
const metadata = JSON.parse(await handler.readFile(`metadata.json`))
// size should be the size of children + grand children + clean after the merge
@@ -418,7 +414,7 @@ describe('tests multiple combination ', () => {
test('it cleans orphan merge states ', async () => {
await handler.writeFile(`${basePath}/.orphan.vhd.merge.json`, '')
await adapter.cleanVm('/', { remove: true })
await adapter.cleanVm('/', { remove: true, logWarn: () => {}, lock: false })
expect(await handler.list(basePath)).toEqual([])
})
@@ -433,7 +429,11 @@ test('check Aliases should work alone', async () => {
await generateVhd(`vhds/data/missingalias.vhd`)
await checkAliases(['vhds/missingData.alias.vhd', 'vhds/ok.alias.vhd'], 'vhds/data', { remove: true, handler })
await checkAliases(['vhds/missingData.alias.vhd', 'vhds/ok.alias.vhd'], 'vhds/data', {
remove: true,
handler,
logWarn: () => {},
})
// only ok have suvived
const alias = (await handler.list('vhds')).filter(f => f.endsWith('.vhd'))

View File

@@ -77,7 +77,7 @@
"private": true,
"scripts": {
"build": "scripts/run-script.js --parallel build",
"ci": "yarn && yarn test-integration",
"ci": "yarn && yarn build && yarn test-integration",
"clean": "scripts/run-script.js --parallel clean",
"dev": "scripts/run-script.js --parallel dev",
"dev-test": "jest --bail --watch \"^(?!.*\\.integ\\.spec\\.js$)\"",

View File

@@ -1,11 +1,13 @@
'use strict'
/* eslint-env jest */
import execa from 'execa'
import rimraf from 'rimraf'
import tmp from 'tmp'
import { pFromCallback } from 'promise-toolbox'
const execa = require('execa')
const rimraf = require('rimraf')
const tmp = require('tmp')
const { pFromCallback } = require('promise-toolbox')
import command from './commands/info'
const command = require('./commands/info')
const initialDir = process.cwd()

View File

@@ -35,5 +35,10 @@
},
"scripts": {
"postversion": "npm publish"
},
"devDependencies": {
"execa": "^4.0.0",
"rimraf": "^3.0.2",
"tmp": "^0.2.1"
}
}

View File

@@ -72,7 +72,7 @@ test('blocks can be moved', async () => {
await newVhd._freeFirstBlockSpace(8000000)
const recoveredFileName = `${tempDir}/recovered`
await recoverRawContent(vhdFileName, recoveredFileName, originalSize)
expect(await fs.readFile(recoveredFileName)).toEqual(await fs.readFile(rawFileName))
expect((await fs.readFile(recoveredFileName)).equals(await fs.readFile(rawFileName))).toEqual(true)
})
test('the BAT MSB is not used for sign', async () => {
@@ -116,7 +116,7 @@ test('the BAT MSB is not used for sign', async () => {
end: hugePositionBytes + randomBuffer.length - 1,
})
)
expect(recovered).toEqual(randomBuffer)
expect(recovered.equals(randomBuffer)).toEqual(true)
})
test('writeData on empty file', async () => {
@@ -134,7 +134,7 @@ test('writeData on empty file', async () => {
await newVhd.writeData(0, randomData)
const recoveredFileName = `${tempDir}/recovered`
await recoverRawContent(emptyFileName, recoveredFileName, originalSize)
expect(await fs.readFile(recoveredFileName)).toEqual(randomData)
expect((await fs.readFile(recoveredFileName)).equals(randomData)).toEqual(true)
})
test('writeData in 2 non-overlaping operations', async () => {
@@ -154,7 +154,7 @@ test('writeData in 2 non-overlaping operations', async () => {
await newVhd.writeData(0, randomData.slice(0, splitPointSectors * 512))
await newVhd.writeData(splitPointSectors, randomData.slice(splitPointSectors * 512))
await recoverRawContent(emptyFileName, recoveredFileName, originalSize)
expect(await fs.readFile(recoveredFileName)).toEqual(randomData)
expect((await fs.readFile(recoveredFileName)).equals(randomData)).toEqual(true)
})
test('writeData in 2 overlaping operations', async () => {
@@ -175,7 +175,7 @@ test('writeData in 2 overlaping operations', async () => {
await newVhd.writeData(0, randomData.slice(0, endFirstWrite * 512))
await newVhd.writeData(startSecondWrite, randomData.slice(startSecondWrite * 512))
await recoverRawContent(emptyFileName, recoveredFileName, originalSize)
expect(await fs.readFile(recoveredFileName)).toEqual(randomData)
expect((await fs.readFile(recoveredFileName)).equals(randomData)).toEqual(true)
})
test('BAT can be extended and blocks moved', async () => {
@@ -193,7 +193,7 @@ test('BAT can be extended and blocks moved', async () => {
await newVhd.ensureBatSize(2000)
await newVhd.writeBlockAllocationTable()
await recoverRawContent(vhdFileName, recoveredFileName, originalSize)
expect(await fs.readFile(recoveredFileName)).toEqual(await fs.readFile(rawFileName))
expect((await fs.readFile(recoveredFileName)).equals(await fs.readFile(rawFileName))).toEqual(true)
})
test('Can coalesce block', async () => {
@@ -227,13 +227,13 @@ test('Can coalesce block', async () => {
await parentVhd.writeBlockAllocationTable()
let parentBlockData = (await parentVhd.readBlock(0)).data
let childBlockData = (await childFileVhd.readBlock(0)).data
expect(parentBlockData).toEqual(childBlockData)
expect(parentBlockData.equals(childBlockData)).toEqual(true)
await parentVhd.mergeBlock(childDirectoryVhd, 0)
await parentVhd.writeFooter()
await parentVhd.writeBlockAllocationTable()
parentBlockData = (await parentVhd.readBlock(0)).data
childBlockData = (await childDirectoryVhd.readBlock(0)).data
expect(parentBlockData).toEqual(childBlockData)
expect(parentBlockData.equals(childBlockData)).toEqual(true)
})
})

View File

@@ -65,25 +65,24 @@ test('It can read block and parent locator from a synthetic vhd', async () => {
const buf = Buffer.alloc(syntheticVhd.sectorsPerBlock * SECTOR_SIZE, 0)
let content = (await syntheticVhd.readBlock(0)).data
await handler.read(smallRawFileName, buf, 0)
expect(content).toEqual(buf)
expect(content.equals(buf)).toEqual(true)
content = (await syntheticVhd.readBlock(1)).data
await handler.read(smallRawFileName, buf, buf.length)
expect(content).toEqual(buf)
expect(content.equals(buf)).toEqual(true)
// the next one from big
content = (await syntheticVhd.readBlock(2)).data
await handler.read(bigRawFileName, buf, buf.length * 2)
expect(content).toEqual(buf)
expect(content.equals(buf)).toEqual(true)
content = (await syntheticVhd.readBlock(3)).data
await handler.read(bigRawFileName, buf, buf.length * 3)
expect(content).toEqual(buf)
expect(content.equals(buf)).toEqual(true)
// the parent locator should the one of the root vhd
const parentLocator = await syntheticVhd.readParentLocator(0)
expect(parentLocator.platformCode).toEqual(PLATFORMS.W2KU)
expect(Buffer.from(parentLocator.data, 'utf-8').toString()).toEqual('I am in the big one')
})
})

View File

@@ -205,7 +205,7 @@ test('it can resume a multiple merge ', async () => {
// should fail since the merge state file has only data of parent and child
await expect(
async () => await mergeVhd(handler, parentFileName, handler, [childFileName, grandChildFileName])
async () => await mergeVhdChain(handler, [parentFileName, childFileName, grandChildFileName])
).rejects.toThrow()
// merge
await handler.unlink(`${tempDir}/.parent.vhd.merge.json`)
@@ -223,7 +223,7 @@ test('it can resume a multiple merge ', async () => {
})
)
// it should succeed
await mergeVhd(handler, parentFileName, handler, [childFileName, grandChildFileName])
await mergeVhdChain(handler, [parentFileName, childFileName, grandChildFileName])
})
test('it merge multiple child in one pass ', async () => {
@@ -284,7 +284,7 @@ test('it cleans vhd mergedfiles', async () => {
await handler.writeFile('child2', 'child2Data')
await handler.writeFile('child3', 'child3Data')
await cleanupVhds(handler, ['parent', 'child1', 'child2', 'child3'], { remove: true })
await cleanupVhds(handler, ['parent', 'child1', 'child2', 'child3'], { merge: true, removeUnused: true })
// only child3 should stay, with the data of parent
const [child3, ...other] = await handler.list('.')

View File

@@ -93,8 +93,8 @@ test('An ova file is generated correctly', async () => {
],
})
await fromEvent(pipe, 'finish')
await execa('tar', ['xf', ovaFileName1, 'vm1.ovf'])
const xml = await readFile('vm1.ovf', { encoding: 'utf-8' })
await execa('tar', ['xf', ovaFileName1, 'metadata.ovf'])
const xml = await readFile('metadata.ovf', { encoding: 'utf-8' })
try {
await execXmllint(xml, [

View File

@@ -8017,6 +8017,21 @@ execa@^2.0.1:
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"
execa@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
integrity sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
human-signals "^1.1.1"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.0"
onetime "^5.1.0"
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"
execa@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
@@ -9929,6 +9944,11 @@ human-format@^1.0.0:
resolved "https://registry.yarnpkg.com/human-format/-/human-format-1.0.0.tgz#bb5ecc618062581f0442769529c553367507e8fe"
integrity sha512-ZfSxF/LHVDb5Un52AguYkZArbiuMbJQwpOpZ0MBuj3pYDmLt7pkCEws9L8xKbgnaKrfMgGd6qc+PHBbKO97AaA==
human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==
human-signals@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
@@ -13251,7 +13271,7 @@ npm-run-path@^3.0.0:
dependencies:
path-key "^3.0.0"
npm-run-path@^4.0.1:
npm-run-path@^4.0.0, npm-run-path@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==