added tests around user volume mounts for prepare job

This commit is contained in:
Nikola Jokic
2022-06-08 11:23:05 +02:00
parent fa680b2073
commit 84a57de2e3
2 changed files with 32 additions and 1 deletions

View File

@@ -52,7 +52,10 @@ export function containerVolumes(
'Volume mounts outside of the work folder are not supported'
)
}
sourceVolumePath = userVolume.sourceVolumePath.slice(workspacePath.length)
// sourcec volume path should be relative path
sourceVolumePath = userVolume.sourceVolumePath.slice(
workspacePath.length + 1
)
} else {
sourceVolumePath = userVolume.sourceVolumePath
}

View File

@@ -40,4 +40,32 @@ describe('Prepare job', () => {
const content = fs.readFileSync(prepareJobOutputFilePath)
expect(() => JSON.parse(content.toString())).not.toThrow()
})
it('should prepare job with absolute path for userVolumeMount', async () => {
prepareJobData.args.container.userMountVolumes.forEach(v => {
if (!path.isAbsolute(v.sourceVolumePath)) {
v.sourceVolumePath = path.join(
process.env.GITHUB_WORKSPACE as string,
v.sourceVolumePath
)
}
})
await expect(
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
).resolves.not.toThrow()
})
it('should throw an exception if the user volume mount is absolute path outside of GITHUB_WORKSPACE', async () => {
prepareJobData.args.container.userMountVolumes.forEach(v => {
if (!path.isAbsolute(v.sourceVolumePath)) {
v.sourceVolumePath = path.join(
'/path/outside/of/github-workspace',
v.sourceVolumePath
)
}
})
await expect(
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
).rejects.toThrow()
})
})