This repository has been archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default Routing for isDefault Ring (#427)
- When a ring is marked as `isDefault: true`, `spk hld reconcile` will now generate an additional IngressRoute and Middleware. - The IngressRoute will not have a `Ring` route match rule - The IngressRoute points to the same backend service as its ringed counterpart. - Only one ring can be marked `isDefault: true` -- validation is run at `spk hld reconcile` execute time, throwing an error if more than one `isDefault`. - Refactored IngressRoute tests - Added compatibility configuration for eslint and prettier. closes microsoft/bedrock#1084
- Loading branch information
Showing
12 changed files
with
634 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
rootDir: "src" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import * as fs from "fs"; | ||
import * as mocks from "../../test/mockFactory"; | ||
import { BedrockFile } from "../../types"; | ||
import * as reconcile from "./reconcile"; | ||
|
||
jest.mock("fs"); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("createMiddlewareForRing", () => { | ||
const tests: { | ||
name: string; | ||
actual: () => unknown; | ||
expected: unknown; | ||
effects?: (() => void)[]; | ||
}[] = [ | ||
{ | ||
name: "isDefault === false; creates one (1) middleware", | ||
actual: (): unknown => | ||
reconcile.createMiddlewareForRing( | ||
"path-to-ring", | ||
"my-service", | ||
"my-ring", | ||
"v1", | ||
false | ||
), | ||
expected: { ringed: expect.anything(), default: undefined }, | ||
effects: [ | ||
(): void => { | ||
expect(fs.writeFileSync).toHaveBeenCalledTimes(1); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
expect.anything(), | ||
expect.not.stringContaining("\n---\n") | ||
); | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "isDefault === true; creates two (2) middleware", | ||
actual: (): unknown => | ||
reconcile.createMiddlewareForRing( | ||
"path-to-ring", | ||
"my-service", | ||
"my-ring", | ||
"v1", | ||
true | ||
), | ||
expected: { | ||
ringed: expect.objectContaining({ | ||
metadata: { name: "my-service-my-ring" }, | ||
}), | ||
default: expect.objectContaining({ metadata: { name: "my-service" } }), | ||
}, | ||
effects: [ | ||
(): void => { | ||
expect(fs.writeFileSync).toHaveBeenCalledTimes(1); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
expect.anything(), | ||
expect.stringContaining("\n---\n") | ||
); | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
for (const { name, actual, expected, effects } of tests) { | ||
it(name, () => { | ||
expect(actual()).toStrictEqual(expected); | ||
for (const effect of effects ?? []) { | ||
effect(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
describe("createIngressRouteForRing", () => { | ||
const { services } = mocks.createTestBedrockYaml(false) as BedrockFile; | ||
const tests: { | ||
name: string; | ||
actual: () => unknown; | ||
expected: unknown; | ||
effects?: (() => void)[]; | ||
}[] = [ | ||
{ | ||
name: "isDefault === false; creates one (1) IngressRoute", | ||
actual: (): unknown => | ||
reconcile.createIngressRouteForRing( | ||
"path-to-ring", | ||
"my-service", | ||
Object.values(services)[0], | ||
{ ringed: { metadata: { name: "my-service-my-ring" } } }, | ||
"my-ring", | ||
"version-path", | ||
false | ||
), | ||
expected: [ | ||
expect.objectContaining({ metadata: { name: "my-service-my-ring" } }), | ||
], | ||
effects: [ | ||
(): void => { | ||
// Should write out one yaml document (no "---") | ||
expect(fs.writeFileSync).toHaveBeenCalledTimes(1); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
expect.anything(), | ||
expect.not.stringContaining("\n---\n") | ||
); | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "isDefault === true; creates two (2) IngressRoute", | ||
actual: (): unknown => | ||
reconcile.createIngressRouteForRing( | ||
"foo", | ||
"my-service", | ||
Object.values(services)[0], | ||
{ ringed: { metadata: { name: "my-service-my-ring" } } }, | ||
"my-ring", | ||
"version-path", | ||
true | ||
), | ||
expected: [ | ||
expect.objectContaining({ metadata: { name: "my-service-my-ring" } }), | ||
expect.objectContaining({ metadata: { name: "my-service" } }), | ||
], | ||
effects: [ | ||
(): void => { | ||
// Should write out two yaml documents (with "---") | ||
expect(fs.writeFileSync).toHaveBeenCalledTimes(1); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith( | ||
expect.anything(), | ||
expect.stringContaining("\n---\n") | ||
); | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
for (const { name, actual, expected, effects } of tests) { | ||
it(name, () => { | ||
expect(actual()).toStrictEqual(expected); | ||
for (const effect of effects ?? []) { | ||
effect(); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.