mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 08:36:45 +00:00
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { prepareJob, cleanupJob, runScriptStep } from '../src/hooks'
|
|
import { TestHelper } from './test-setup'
|
|
import * as path from 'path'
|
|
import * as fs from 'fs'
|
|
|
|
jest.useRealTimers()
|
|
|
|
let testHelper: TestHelper
|
|
|
|
const prepareJobJsonPath = path.resolve(
|
|
`${__dirname}/../../../examples/prepare-job.json`
|
|
)
|
|
let prepareJobData: any
|
|
|
|
let prepareJobOutputFilePath: string
|
|
let prepareJobOutputData: any
|
|
|
|
describe('Run script step', () => {
|
|
beforeEach(async () => {
|
|
const prepareJobJson = fs.readFileSync(prepareJobJsonPath)
|
|
prepareJobData = JSON.parse(prepareJobJson.toString())
|
|
|
|
testHelper = new TestHelper()
|
|
await testHelper.initialize()
|
|
prepareJobOutputFilePath = testHelper.createFile('prepare-job-output.json')
|
|
await prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
|
const outputContent = fs.readFileSync(prepareJobOutputFilePath)
|
|
prepareJobOutputData = JSON.parse(outputContent.toString())
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await cleanupJob()
|
|
await testHelper.cleanup()
|
|
})
|
|
|
|
// NOTE: To use this test, do kubectl apply -f podspec.yaml (from podspec examples)
|
|
// then change the name of the file to 'run-script-step-test.ts' and do
|
|
// npm run test run-script-step
|
|
|
|
it('should not throw an exception', async () => {
|
|
const args = {
|
|
entryPointArgs: ['-c', 'echo "test"'],
|
|
entryPoint: 'bash',
|
|
environmentVariables: {
|
|
NODE_ENV: 'development'
|
|
},
|
|
prependPath: ['/foo/bar', 'bar/foo'],
|
|
workingDirectory: '/__w/thboop-test2/thboop-test2'
|
|
}
|
|
const state = {
|
|
jobPod: prepareJobOutputData.state.jobPod
|
|
}
|
|
const responseFile = null
|
|
await expect(
|
|
runScriptStep(args, state, responseFile)
|
|
).resolves.not.toThrow()
|
|
})
|
|
})
|