mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-07-01 01:39:26 +08:00
Fixed Blue/Green Strategy Ingress Route-Method Glitch (#217)
* Added some tests, not sure what else to try but gonna think of more examples * forgot some files * reverted package-lock.json * Added empty dir test * Cleaned up some extra spaces * Add node modules and compiled JavaScript from main * forgot to actually include functionality * removed unnecessary files * Update .gitignore * Update .gitignore * Update .gitignore * thx david * renamed searchFilesRec * integrations test fix * added examples to README * added note about depth * added additional note * removed ticks * changed version string * removed conflict on readme * Added tests for bluegreen helper and resolved issue with ingress not being read correctly, still have to figure out why new services aren't showing up * resolved services name issue * looks functional, beginning refactor now * refactored deploy methods for type error * Removed refactor comments * prettier * implemented Oliver's feedback * prettier * added optional chaining operator * removed refactor comment Co-authored-by: Jaiveer Katariya <jaiveerkatariya@Jaiveers-MacBook-Pro.local> Co-authored-by: Oliver King <oking3@uncc.edu> Co-authored-by: Jaiveer Katariya <jaiveerkatariya@Jaiveers-MBP.lan>
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
createWorkloadsWithLabel,
|
||||
deleteWorkloadsAndServicesWithLabel,
|
||||
getManifestObjects,
|
||||
getNewBlueGreenObject,
|
||||
GREEN_LABEL_VALUE,
|
||||
isServiceRouted,
|
||||
NONE_LABEL_VALUE
|
||||
} from './blueGreenHelper'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
|
||||
describe('bluegreenhelper functions', () => {
|
||||
let testObjects
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
testObjects = getManifestObjects(['test/unit/manifests/test-ingress.yml'])
|
||||
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
})
|
||||
|
||||
test('it should parse objects correctly from one file', () => {
|
||||
expect(testObjects.deploymentEntityList[0].kind).toBe('Deployment')
|
||||
expect(testObjects.serviceEntityList[0].kind).toBe('Service')
|
||||
expect(testObjects.ingressEntityList[0].kind).toBe('Ingress')
|
||||
|
||||
expect(
|
||||
testObjects.deploymentEntityList[0].spec.selector.matchLabels.app
|
||||
).toBe('nginx')
|
||||
})
|
||||
|
||||
test('correctly makes new blue green object', () => {
|
||||
const modifiedDeployment = getNewBlueGreenObject(
|
||||
testObjects.deploymentEntityList[0],
|
||||
GREEN_LABEL_VALUE
|
||||
)
|
||||
//@ts-ignore
|
||||
expect(modifiedDeployment.metadata.name).toBe('nginx-deployment-green')
|
||||
//@ts-ignore
|
||||
expect(modifiedDeployment.metadata.labels['k8s.deploy.color']).toBe(
|
||||
'green'
|
||||
)
|
||||
|
||||
const modifiedSvc = getNewBlueGreenObject(
|
||||
testObjects.serviceEntityList[0],
|
||||
GREEN_LABEL_VALUE
|
||||
)
|
||||
//@ts-ignore
|
||||
expect(modifiedSvc.metadata.name).toBe('nginx-service-green')
|
||||
//@ts-ignore
|
||||
expect(modifiedSvc.metadata.labels['k8s.deploy.color']).toBe('green')
|
||||
})
|
||||
|
||||
test('correctly makes labeled workloads', () => {
|
||||
const kubectl = new Kubectl('')
|
||||
expect(Kubectl).toBeCalledTimes(1)
|
||||
const cwlResult = createWorkloadsWithLabel(
|
||||
kubectl,
|
||||
testObjects.deploymentEntityList,
|
||||
GREEN_LABEL_VALUE
|
||||
)
|
||||
cwlResult.then((value) => {
|
||||
//@ts-ignore
|
||||
expect(value.newFilePaths[0]).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
test('correctly classifies routed services', () => {
|
||||
expect(
|
||||
isServiceRouted(
|
||||
testObjects.serviceEntityList[0],
|
||||
testObjects.deploymentEntityList
|
||||
)
|
||||
).toBe(true)
|
||||
testObjects.serviceEntityList[0].spec.selector.app = 'fakeapp'
|
||||
expect(
|
||||
isServiceRouted(
|
||||
testObjects.serviceEntityList[0],
|
||||
testObjects.deploymentEntityList
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
test('correctly deletes services and workloads according to label', () => {
|
||||
const kubectl = new Kubectl('')
|
||||
jest.spyOn(bgHelper, 'deleteObjects').mockReturnValue({} as Promise<void>)
|
||||
|
||||
let objectsToDelete = deleteWorkloadsAndServicesWithLabel(
|
||||
kubectl,
|
||||
NONE_LABEL_VALUE,
|
||||
testObjects.deploymentEntityList,
|
||||
testObjects.serviceEntityList
|
||||
)
|
||||
objectsToDelete.then((value) => {
|
||||
expect(value).toHaveLength(2)
|
||||
expect(value).toContainEqual
|
||||
;({name: 'nginx-service', kind: 'Service'})
|
||||
expect(value).toContainEqual({
|
||||
name: 'nginx-deployment',
|
||||
kind: 'Deployment'
|
||||
})
|
||||
})
|
||||
|
||||
objectsToDelete = deleteWorkloadsAndServicesWithLabel(
|
||||
kubectl,
|
||||
GREEN_LABEL_VALUE,
|
||||
testObjects.deploymentEntityList,
|
||||
testObjects.serviceEntityList
|
||||
)
|
||||
objectsToDelete.then((value) => {
|
||||
expect(value).toHaveLength(2)
|
||||
expect(value).toContainEqual({
|
||||
name: 'nginx-service-green',
|
||||
kind: 'Service'
|
||||
})
|
||||
expect(value).toContainEqual({
|
||||
name: 'nginx-deployment-green',
|
||||
kind: 'Deployment'
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user