feat(vhd-lib): tests shouldn't need root access to run
This commit is contained in:
@@ -55,9 +55,9 @@ test('It creates an alias', async () => {
|
||||
|
||||
test('alias must have *.alias.vhd extension', async () => {
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const aliasPath = `${tempDir}/invalidalias.vhd`
|
||||
const targetPath = `${tempDir}/targets.vhd`
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
const aliasPath = 'invalidalias.vhd'
|
||||
const targetPath = 'targets.vhd'
|
||||
expect(async () => await VhdAbstract.createAlias(handler, aliasPath, targetPath)).rejects.toThrow()
|
||||
|
||||
expect(await fs.exists(aliasPath)).toEqual(false)
|
||||
@@ -66,9 +66,9 @@ test('alias must have *.alias.vhd extension', async () => {
|
||||
|
||||
test('alias must not be chained', async () => {
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const aliasPath = `${tempDir}/valid.alias.vhd`
|
||||
const targetPath = `${tempDir}/an.other.valid.alias.vhd`
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
const aliasPath = 'valid.alias.vhd'
|
||||
const targetPath = 'an.other.valid.alias.vhd'
|
||||
expect(async () => await VhdAbstract.createAlias(handler, aliasPath, targetPath)).rejects.toThrow()
|
||||
expect(await fs.exists(aliasPath)).toEqual(false)
|
||||
})
|
||||
@@ -78,19 +78,17 @@ test('It rename and unlink a VHDFile', async () => {
|
||||
const initalSize = 4
|
||||
const rawFileName = `${tempDir}/randomfile`
|
||||
await createRandomFile(rawFileName, initalSize)
|
||||
const vhdFileName = `${tempDir}/randomfile.vhd`
|
||||
await convertFromRawToVhd(rawFileName, vhdFileName)
|
||||
await convertFromRawToVhd(rawFileName, `${tempDir}/randomfile.vhd`)
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const { size } = await fs.stat(vhdFileName)
|
||||
const targetFileName = `${tempDir}/renamed.vhd`
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
const { size } = await fs.stat(`${tempDir}/randomfile.vhd`)
|
||||
|
||||
await VhdAbstract.rename(handler, vhdFileName, targetFileName)
|
||||
expect(await fs.exists(vhdFileName)).toEqual(false)
|
||||
const { size: renamedSize } = await fs.stat(targetFileName)
|
||||
await VhdAbstract.rename(handler, 'randomfile.vhd', 'renamed.vhd')
|
||||
expect(await fs.exists(`${tempDir}/randomfile.vhd`)).toEqual(false)
|
||||
const { size: renamedSize } = await fs.stat(`${tempDir}/renamed.vhd`)
|
||||
expect(size).toEqual(renamedSize)
|
||||
await VhdAbstract.unlink(handler, targetFileName)
|
||||
expect(await fs.exists(targetFileName)).toEqual(false)
|
||||
await VhdAbstract.unlink(handler, 'renamed.vhd')
|
||||
expect(await fs.exists(`${tempDir}/renamed.vhd`)).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -100,16 +98,15 @@ test('It rename and unlink a VhdDirectory', async () => {
|
||||
await createRandomVhdDirectory(vhdDirectory, initalSize)
|
||||
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const vhd = yield openVhd(handler, vhdDirectory)
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
const vhd = yield openVhd(handler, 'randomfile.dir')
|
||||
expect(vhd.header.cookie).toEqual('cxsparse')
|
||||
expect(vhd.footer.cookie).toEqual('conectix')
|
||||
|
||||
const targetFileName = `${tempDir}/renamed.vhd`
|
||||
await VhdAbstract.rename(handler, vhdDirectory, targetFileName)
|
||||
expect(await fs.exists(vhdDirectory)).toEqual(false)
|
||||
await VhdAbstract.unlink(handler, targetFileName)
|
||||
expect(await fs.exists(targetFileName)).toEqual(false)
|
||||
await VhdAbstract.rename(handler, 'randomfile.dir', 'renamed.vhd')
|
||||
expect(await fs.exists(`${tempDir}/randomfile.dir`)).toEqual(false)
|
||||
await VhdAbstract.unlink(handler, `renamed.vhd`)
|
||||
expect(await fs.exists(`${tempDir}/renamed.vhd`)).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -123,17 +120,17 @@ test('It create , rename and unlink alias', async () => {
|
||||
const aliasFileNameRenamed = `${tempDir}/aliasFileNameRenamed.alias.vhd`
|
||||
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
await VhdAbstract.createAlias(handler, aliasFileName, vhdFileName)
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
await VhdAbstract.createAlias(handler, 'aliasFileName.alias.vhd', 'randomfile.vhd')
|
||||
expect(await fs.exists(aliasFileName)).toEqual(true)
|
||||
expect(await fs.exists(vhdFileName)).toEqual(true)
|
||||
|
||||
await VhdAbstract.rename(handler, aliasFileName, aliasFileNameRenamed)
|
||||
await VhdAbstract.rename(handler, 'aliasFileName.alias.vhd', 'aliasFileNameRenamed.alias.vhd')
|
||||
expect(await fs.exists(aliasFileName)).toEqual(false)
|
||||
expect(await fs.exists(vhdFileName)).toEqual(true)
|
||||
expect(await fs.exists(aliasFileNameRenamed)).toEqual(true)
|
||||
|
||||
await VhdAbstract.unlink(handler, aliasFileNameRenamed)
|
||||
await VhdAbstract.unlink(handler, 'aliasFileNameRenamed.alias.vhd')
|
||||
expect(await fs.exists(aliasFileName)).toEqual(false)
|
||||
expect(await fs.exists(vhdFileName)).toEqual(false)
|
||||
expect(await fs.exists(aliasFileNameRenamed)).toEqual(false)
|
||||
|
||||
@@ -32,24 +32,34 @@ test('resolve return the path in argument for a non alias file ', async () => {
|
||||
test('resolve get the path of the target file for an alias', async () => {
|
||||
await Disposable.use(async function* () {
|
||||
// same directory
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const tempDirFomRemoteUrl = tempDir.slice(1) // remove the / which is included in the remote url
|
||||
const alias = `${tempDirFomRemoteUrl}/alias.alias.vhd`
|
||||
await handler.writeFile(alias, 'target.vhd')
|
||||
expect(await resolveAlias(handler, alias)).toEqual(`${tempDirFomRemoteUrl}/target.vhd`)
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
await handler.mkdir(`alias`)
|
||||
const aliasPath = 'alias/alias.alias.vhd'
|
||||
const testOneCombination = async ({ targetPath, targetContent }) => {
|
||||
await handler.writeFile(aliasPath, targetPath, { flags: 'w' })
|
||||
const resolved = await resolveAlias(handler, aliasPath)
|
||||
expect(resolved).toEqual(targetContent)
|
||||
await handler.unlink(aliasPath)
|
||||
}
|
||||
// the alias contain the relative path to the file. The resolved values is the full path from the root of the remote
|
||||
const combinations = [
|
||||
{ targetPath: `../targets.vhd`, targetContent: `targets.vhd` },
|
||||
{ targetPath: `targets.vhd`, targetContent: `alias/targets.vhd` },
|
||||
{ targetPath: `sub/targets.vhd`, targetContent: `alias/sub/targets.vhd` },
|
||||
{ targetPath: `../sibling/targets.vhd`, targetContent: `sibling/targets.vhd` },
|
||||
]
|
||||
|
||||
// different directory
|
||||
await handler.mkdir(`${tempDirFomRemoteUrl}/sub/`)
|
||||
await handler.writeFile(alias, 'sub/target.vhd', { flags: 'w' })
|
||||
expect(await resolveAlias(handler, alias)).toEqual(`${tempDirFomRemoteUrl}/sub/target.vhd`)
|
||||
for (const { targetPath, targetContent } of combinations) {
|
||||
await testOneCombination({ targetPath, targetContent })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('resolve throws an error an alias to an alias', async () => {
|
||||
await Disposable.use(async function* () {
|
||||
const handler = yield getSyncedHandler({ url: 'file:///' })
|
||||
const alias = `${tempDir}/alias.alias.vhd`
|
||||
const target = `${tempDir}/target.alias.vhd`
|
||||
const handler = yield getSyncedHandler({ url: `file://${tempDir}` })
|
||||
const alias = 'alias.alias.vhd'
|
||||
const target = 'target.alias.vhd'
|
||||
await handler.writeFile(alias, target)
|
||||
expect(async () => await resolveAlias(handler, alias)).rejects.toThrow(Error)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user