mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-27 09:39:27 +08:00
separate action and execution (#77)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import {getRequiredInputError} from '../tests/util'
|
||||
import {run} from './action'
|
||||
import fs from 'fs'
|
||||
import * as utils from './utils'
|
||||
|
||||
describe('Run', () => {
|
||||
it('throws error without cluster type', async () => {
|
||||
await expect(run()).rejects.toThrow(getRequiredInputError('cluster-type'))
|
||||
})
|
||||
|
||||
it('writes kubeconfig and sets context', async () => {
|
||||
const kubeconfig = 'kubeconfig'
|
||||
|
||||
process.env['INPUT_CLUSTER-TYPE'] = 'default'
|
||||
process.env['RUNNER_TEMP'] = '/sample/path'
|
||||
|
||||
jest
|
||||
.spyOn(utils, 'getKubeconfig')
|
||||
.mockImplementation(async () => kubeconfig)
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest.spyOn(utils, 'setContext').mockImplementation(() => kubeconfig)
|
||||
|
||||
expect(await run())
|
||||
expect(utils.getKubeconfig).toHaveBeenCalled()
|
||||
expect(fs.writeFileSync).toHaveBeenCalled()
|
||||
expect(fs.chmodSync).toHaveBeenCalled()
|
||||
expect(utils.setContext).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user