mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-21 10:39:26 +08:00
00795b0b56
* changed ubuntu runner
* changed minikube action
* Version formatting
* nonedriveR
* update kube version
* installing conntrack'
* updated other actions
* update bg ingress api version
* prettify
* updated ingress backend for new api version
* Added path type
* prettify
* added logging
* added try catch logic to prevent future failures if annotations fail since failing annotations shouldn't affect users
* added nullcheck
* Added fallback filename if workflow fails to get github filepath due to runner issues
* cleanup
* added oliver's feedback + unit test demonstrating regex glitch and fix
* no longer using blank string for failed regex
* add tests and dont split so much
* testing
* file fix
* without fix
* Revert "without fix"
This reverts commit 8da79a8190.
* fixing labels test
* pretty
---------
Co-authored-by: David Gamero <david340804@gmail.com>
47 lines
2.9 KiB
TypeScript
47 lines
2.9 KiB
TypeScript
import {
|
|
PrivateKubectl,
|
|
extractFileNames,
|
|
replaceFileNamesWithBaseNames
|
|
} from './privatekubectl'
|
|
import * as exec from '@actions/exec'
|
|
|
|
describe('Private kubectl', () => {
|
|
const testString = `kubectl annotate -f testdir/test.yml,test2.yml,testdir/subdir/test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
|
const mockKube = new PrivateKubectl(
|
|
'kubectlPath',
|
|
'namespace',
|
|
true,
|
|
'resourceGroup',
|
|
'resourceName'
|
|
)
|
|
|
|
it('should extract filenames correctly', () => {
|
|
expect(extractFileNames(testString)).toEqual([
|
|
'testdir/test.yml',
|
|
'test2.yml',
|
|
'testdir/subdir/test3.yml',
|
|
'test4.yml',
|
|
'test5.yml'
|
|
])
|
|
})
|
|
|
|
it('should replace filenames with basenames correctly', () => {
|
|
expect(replaceFileNamesWithBaseNames(testString)).toEqual(
|
|
`kubectl annotate -f test.yml,test2.yml,test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
|
)
|
|
})
|
|
|
|
test('Should throw well defined Error on error from Azure', async () => {
|
|
const errorMsg = 'An error message'
|
|
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
|
return {exitCode: 1, stdout: '', stderr: errorMsg}
|
|
})
|
|
|
|
await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
|
|
Error(
|
|
`Call to private cluster failed. Command: 'kubectl az test --insecure-skip-tls-verify --namespace namespace', errormessage: ${errorMsg}`
|
|
)
|
|
)
|
|
})
|
|
})
|