mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-13 08:06:44 +00:00
* Implement yaml extensions overwriting the default pod/container spec * format files * Extend specs for container job and include docker and k8s tests in k8s * Create table tests for docker tests * included warnings and extracted append logic as generic * updated merge to allow for file read * reverted back examples and k8s/tests * reverted back docker tests * Tests for extension prepare-job * Fix lint and format and merge error * Added basic test for container step * revert hooklib since new definition for container options is received from a file * revert docker options since create options are a string * Fix revert * Update package locks and deps * included example of extension.yaml. Added side-car container that was missing * Ignore spec modification for the service containers, change selector to * fix lint error * Add missing image override * Add comment explaining merge object meta with job and pod * fix test
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { runContainerStep } from '../src/hooks'
|
|
import { TestHelper } from './test-setup'
|
|
import { ENV_HOOK_TEMPLATE_PATH } from '../src/k8s/utils'
|
|
import * as fs from 'fs'
|
|
import * as yaml from 'js-yaml'
|
|
import { JOB_CONTAINER_EXTENSION_NAME } from '../src/hooks/constants'
|
|
|
|
jest.useRealTimers()
|
|
|
|
let testHelper: TestHelper
|
|
|
|
let runContainerStepData: any
|
|
|
|
describe('Run container step', () => {
|
|
beforeEach(async () => {
|
|
testHelper = new TestHelper()
|
|
await testHelper.initialize()
|
|
runContainerStepData = testHelper.getRunContainerStepDefinition()
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testHelper.cleanup()
|
|
})
|
|
|
|
it('should not throw', async () => {
|
|
const exitCode = await runContainerStep(runContainerStepData.args)
|
|
expect(exitCode).toBe(0)
|
|
})
|
|
|
|
it('should run pod with extensions applied', async () => {
|
|
const extension = {
|
|
metadata: {
|
|
annotations: {
|
|
foo: 'bar'
|
|
},
|
|
labels: {
|
|
bar: 'baz'
|
|
}
|
|
},
|
|
spec: {
|
|
containers: [
|
|
{
|
|
name: JOB_CONTAINER_EXTENSION_NAME,
|
|
command: ['sh'],
|
|
args: ['-c', 'echo test']
|
|
},
|
|
{
|
|
name: 'side-container',
|
|
image: 'ubuntu:latest',
|
|
command: ['sh'],
|
|
args: ['-c', 'echo test']
|
|
}
|
|
],
|
|
restartPolicy: 'Never',
|
|
securityContext: {
|
|
runAsUser: 1000,
|
|
runAsGroup: 3000
|
|
}
|
|
}
|
|
}
|
|
|
|
let filePath = testHelper.createFile()
|
|
fs.writeFileSync(filePath, yaml.dump(extension))
|
|
process.env[ENV_HOOK_TEMPLATE_PATH] = filePath
|
|
await expect(
|
|
runContainerStep(runContainerStepData.args)
|
|
).resolves.not.toThrow()
|
|
delete process.env[ENV_HOOK_TEMPLATE_PATH]
|
|
})
|
|
|
|
it('should shold have env variables available', async () => {
|
|
runContainerStepData.args.entryPoint = 'bash'
|
|
runContainerStepData.args.entryPointArgs = [
|
|
'-c',
|
|
'if [[ -z $NODE_ENV ]]; then exit 1; fi'
|
|
]
|
|
await expect(
|
|
runContainerStep(runContainerStepData.args)
|
|
).resolves.not.toThrow()
|
|
})
|
|
})
|