Files
runner-container-hooks/packages/docker/tests/e2e-test.ts
Nikola Jokic 8ea57170d8 Fix working directory and write state for appPod to be used in run-script-step (#8)
* added initial entrypoint script

* change workingg directory working with addition to fix prepare-job state output

* added prepend path

* added run-script-step file generation, removed prepend path from container-step and prepare job

* latest changes with testing run script step

* fix the mounts real fast

* cleanup

* fix tests

* add kind test

* add kind yaml to ignore and run it during ci

* fix kind option

* remove gitignore

* lowercase pwd

* checkout first!

* ignore test file in build.yaml

* fixed wrong working directory and added test to run script step testing for the env

* handle env's/escaping better

* added single quote escape to env escapes

* surounded env value with single quote

* added spacing around run-container-step, changed examples to actually echo hello world

* refactored tests

* make sure to escape properly

* set addition mounts for container steps

* fixup container action mounts

Co-authored-by: Thomas Boop <thboop@github.com>
Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>
2022-06-14 21:41:49 -04:00

91 lines
2.3 KiB
TypeScript

import * as fs from 'fs'
import {
cleanupJob,
prepareJob,
runContainerStep,
runScriptStep
} from '../src/hooks'
import TestSetup from './test-setup'
let definitions
let testSetup: TestSetup
describe('e2e', () => {
beforeEach(() => {
testSetup = new TestSetup()
testSetup.initialize()
definitions = {
prepareJob: testSetup.getPrepareJobDefinition(),
runScriptStep: testSetup.getRunScriptStepDefinition(),
runContainerStep: testSetup.getRunContainerStepDefinition()
}
})
afterEach(() => {
testSetup.teardown()
})
it('should prepare job, then run script step, then run container step then cleanup', async () => {
const prepareJobOutput = testSetup.createOutputFile(
'prepare-job-output.json'
)
await expect(
prepareJob(definitions.prepareJob.args, prepareJobOutput)
).resolves.not.toThrow()
let rawState = fs.readFileSync(prepareJobOutput, 'utf-8')
let resp = JSON.parse(rawState)
await expect(
runScriptStep(definitions.runScriptStep.args, resp.state)
).resolves.not.toThrow()
await expect(
runContainerStep(definitions.runContainerStep.args, resp.state)
).resolves.not.toThrow()
await expect(cleanupJob()).resolves.not.toThrow()
})
it('should prepare job, then run script step, then run container step with Dockerfile then cleanup', async () => {
const prepareJobOutput = testSetup.createOutputFile(
'prepare-job-output.json'
)
await expect(
prepareJob(definitions.prepareJob.args, prepareJobOutput)
).resolves.not.toThrow()
let rawState = fs.readFileSync(prepareJobOutput, 'utf-8')
let resp = JSON.parse(rawState)
await expect(
runScriptStep(definitions.runScriptStep.args, resp.state)
).resolves.not.toThrow()
const dockerfilePath = `${testSetup.workingDirectory}/Dockerfile`
fs.writeFileSync(
dockerfilePath,
`FROM ubuntu:latest
ENV TEST=test
ENTRYPOINT [ "tail", "-f", "/dev/null" ]
`
)
const containerStepDataCopy = JSON.parse(
JSON.stringify(definitions.runContainerStep)
)
containerStepDataCopy.args.dockerfile = 'Dockerfile'
await expect(
runContainerStep(containerStepDataCopy.args, resp.state)
).resolves.not.toThrow()
await expect(cleanupJob()).resolves.not.toThrow()
})
})