Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions jest.config.js
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"
};
151 changes: 151 additions & 0 deletions src/commands/hld/reconcile-unit.test.ts
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();
}
});
}
});
4 changes: 2 additions & 2 deletions src/commands/hld/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import { create as createBedrockYaml } from "../../lib/bedrockYaml";
import { disableVerboseLogging, enableVerboseLogging } from "../../logger";
import { BedrockFile, BedrockServiceConfig } from "../../types";
import * as reconcile from "./reconcile";
import {
addChartToRing,
checkForFabrikate,
Expand All @@ -14,13 +15,12 @@ import {
execAndLog,
execute,
getFullPathPrefix,
ReconcileDependencies,
normalizedName,
ReconcileDependencies,
reconcileHld,
testAndGetAbsPath,
validateInputs,
} from "./reconcile";
import * as reconcile from "./reconcile";

beforeAll(() => {
enableVerboseLogging();
Expand Down
Loading