mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-07-02 19:09:28 +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,88 @@
|
||||
import {getManifestObjects, GREEN_LABEL_VALUE} from './blueGreenHelper'
|
||||
import {
|
||||
deployBlueGreenIngress,
|
||||
getUpdatedBlueGreenIngress,
|
||||
isIngressRouted,
|
||||
routeBlueGreenIngress
|
||||
} from './ingressBlueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
|
||||
describe('ingress blue green helpers', () => {
|
||||
let testObjects
|
||||
const betaFilepath = ['test/unit/manifests/test-ingress.yml']
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
})
|
||||
|
||||
test('it should correctly classify ingresses', () => {
|
||||
expect(
|
||||
isIngressRouted(
|
||||
testObjects.ingressEntityList[0],
|
||||
testObjects.serviceNameMap
|
||||
)
|
||||
).toBe(true)
|
||||
testObjects.ingressEntityList[0].spec.rules[0].http.paths = {}
|
||||
expect(
|
||||
isIngressRouted(
|
||||
testObjects.ingressEntityList[0],
|
||||
testObjects.serviceNameMap
|
||||
)
|
||||
).toBe(false)
|
||||
|
||||
expect(
|
||||
isIngressRouted(
|
||||
getManifestObjects(betaFilepath).ingressEntityList[0],
|
||||
testObjects.serviceNameMap
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test('it should correctly update ingresses', () => {
|
||||
const updatedIng = getUpdatedBlueGreenIngress(
|
||||
testObjects.ingressEntityList[0],
|
||||
testObjects.serviceNameMap,
|
||||
GREEN_LABEL_VALUE
|
||||
)
|
||||
//@ts-ignore
|
||||
expect(updatedIng.metadata.labels['k8s.deploy.color']).toBe('green')
|
||||
//@ts-ignore
|
||||
expect(updatedIng.spec.rules[0].http.paths[0].backend.service.name).toBe(
|
||||
'nginx-service-green'
|
||||
)
|
||||
})
|
||||
|
||||
test('correctly prepares blue/green ingresses for deployment', () => {
|
||||
const kc = new Kubectl('')
|
||||
const generatedObjects = routeBlueGreenIngress(
|
||||
kc,
|
||||
GREEN_LABEL_VALUE,
|
||||
testObjects.serviceNameMap,
|
||||
testObjects.ingressEntityList
|
||||
)
|
||||
generatedObjects.then((value) => {
|
||||
expect(value).toHaveLength(1)
|
||||
//@ts-ignore
|
||||
expect(value[0].metadata.name).toBe('nginx-ingress')
|
||||
})
|
||||
})
|
||||
test('correctly deploys services', () => {
|
||||
const kc = new Kubectl('')
|
||||
const result = deployBlueGreenIngress(kc, ingressFilepath)
|
||||
|
||||
result.then((value) => {
|
||||
const nol = value.newObjectsList
|
||||
//@ts-ignore
|
||||
expect(nol[0].metadata.name).toBe('nginx-service-green')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user