Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 1cc3263

Browse files
authored
fix eslint warnings/errors in Deployment Dashboard command (#449)
1 parent 8724e40 commit 1cc3263

File tree

2 files changed

+120
-104
lines changed

2 files changed

+120
-104
lines changed

src/commands/deployment/dashboard.test.ts

+47-40
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
logger,
1212
} from "../../logger";
1313
import {
14+
DashboardConfig,
1415
execute,
1516
extractManifestRepositoryInformation,
1617
getEnvVars,
@@ -20,6 +21,20 @@ import {
2021
import * as dashboard from "./dashboard";
2122

2223
import uuid from "uuid/v4";
24+
import { deepClone } from "../../lib/util";
25+
26+
const dashboardConf: DashboardConfig = {
27+
port: 2020,
28+
image: "mcr.microsoft.com/k8s/bedrock/spektate:latest",
29+
org: "testOrg",
30+
project: "testProject",
31+
key: "fakeKey",
32+
accountName: "fakeAccount",
33+
tableName: "fakeTable",
34+
partitionKey: "fakePartitionKey",
35+
accessToken: "accessToken",
36+
sourceRepoAccessToken: "test_token",
37+
};
2338

2439
beforeAll(() => {
2540
enableVerboseLogging();
@@ -37,6 +52,10 @@ const mockConfig = (): void => {
3752
project: uuid(),
3853
},
3954
introspection: {
55+
dashboard: {
56+
image: "mcr.microsoft.com/k8s/bedrock/spektate:latest",
57+
name: "spektate",
58+
},
4059
azure: {
4160
account_name: uuid(),
4261
key: uuid(),
@@ -81,8 +100,7 @@ describe("Test validateValues function", () => {
81100
});
82101
it("positive test", () => {
83102
mockConfig();
84-
const config = Config();
85-
validateValues(config, {
103+
validateValues(Config(), {
86104
port: "4000",
87105
removeAll: false,
88106
});
@@ -96,7 +114,7 @@ describe("Test execute function", () => {
96114
jest
97115
.spyOn(dashboard, "launchDashboard")
98116
.mockReturnValueOnce(Promise.resolve(uuid()));
99-
jest.spyOn(dashboard, "validateValues").mockReturnValueOnce();
117+
jest.spyOn(dashboard, "validateValues").mockReturnValueOnce(dashboardConf);
100118
(open as jest.Mock).mockReturnValueOnce(Promise.resolve());
101119
await execute(
102120
{
@@ -125,16 +143,13 @@ describe("Test execute function", () => {
125143
describe("Validate dashboard container pull", () => {
126144
test("Pull dashboard container if docker is installed", async () => {
127145
try {
128-
mockConfig();
129-
const config = Config();
130-
const dashboardContainerId = await launchDashboard(config, 2020, false);
146+
const dashboardContainerId = await launchDashboard(dashboardConf, false);
131147
const dockerInstalled = validatePrereqs(["docker"], false);
132148
if (dockerInstalled) {
133149
const dockerId = await exec("docker", [
134150
"images",
135151
"-q",
136-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137-
config.introspection!.dashboard!.image!,
152+
dashboardConf.image,
138153
]);
139154
expect(dockerId).toBeDefined();
140155
expect(dashboardContainerId).not.toBe("");
@@ -152,22 +167,22 @@ describe("Validate dashboard container pull", () => {
152167
describe("Validate dashboard clean up", () => {
153168
test("Launch the dashboard two times", async () => {
154169
try {
155-
mockConfig();
156-
const config = Config();
157-
const dashboardContainerId = await launchDashboard(config, 2020, true);
170+
const dashboardContainerId = await launchDashboard(dashboardConf, true);
158171
const dockerInstalled = validatePrereqs(["docker"], false);
159172
if (dockerInstalled) {
160173
const dockerId = await exec("docker", [
161174
"images",
162175
"-q",
163-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
164-
config.introspection!.dashboard!.image!,
176+
dashboardConf.image,
165177
]);
166178

167179
expect(dockerId).toBeDefined();
168180
expect(dashboardContainerId).not.toBe("");
169181
logger.info("Verified that docker image has been pulled.");
170-
const dashboardContainerId2 = await launchDashboard(config, 2020, true);
182+
const dashboardContainerId2 = await launchDashboard(
183+
dashboardConf,
184+
true
185+
);
171186
expect(dashboardContainerId).not.toBe(dashboardContainerId2);
172187
await exec("docker", ["container", "stop", dashboardContainerId2]);
173188
} else {
@@ -183,7 +198,7 @@ describe("Fallback to azure devops access token", () => {
183198
test("Has repo_access_token specified", async () => {
184199
mockConfig();
185200
const config = Config();
186-
const envVars = (await getEnvVars(config)).toString();
201+
const envVars = (await getEnvVars(dashboardConf)).toString();
187202
logger.info(
188203
`spin: ${envVars}, act: ${
189204
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -195,41 +210,33 @@ describe("Fallback to azure devops access token", () => {
195210
});
196211

197212
it("No repo_access_token was specified", async () => {
198-
mockConfig();
199-
const config = Config();
200-
const envVars = (await getEnvVars(config)).toString();
201-
const expectedSubstring =
202-
"REACT_APP_SOURCE_REPO_ACCESS_TOKEN=" +
203-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
204-
config.introspection!.azure!.source_repo_access_token!;
213+
const envVars = (await getEnvVars(dashboardConf)).toString();
214+
const expectedSubstring = `REACT_APP_SOURCE_REPO_ACCESS_TOKEN=${dashboardConf.sourceRepoAccessToken}`;
205215
expect(envVars.includes(expectedSubstring)).toBeTruthy();
206216
});
207217
});
208218

209219
describe("Extract manifest repository information", () => {
210220
test("Manifest repository information is successfully extracted", () => {
211-
(Config as jest.Mock).mockReturnValue({
212-
azure_devops: {
213-
manifest_repository:
214-
"https://dev.azure.com/bhnook/fabrikam/_git/materialized",
215-
},
216-
});
217-
const config = Config();
221+
const config = deepClone(dashboardConf);
222+
config.manifestRepository =
223+
"https://dev.azure.com/bhnook/fabrikam/_git/materialized";
224+
218225
let manifestInfo = extractManifestRepositoryInformation(config);
219226
expect(manifestInfo).toBeDefined();
220-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
221-
expect(manifestInfo!.githubUsername).toBeUndefined();
222-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
223-
expect(manifestInfo!.manifestRepoName).toBe("materialized");
224-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
225-
config.azure_devops!["manifest_repository"] =
226-
"https://github.com/username/manifest";
227+
if (manifestInfo) {
228+
expect(manifestInfo.githubUsername).toBeUndefined();
229+
expect(manifestInfo.manifestRepoName).toBe("materialized");
230+
}
231+
232+
config.manifestRepository = "https://github.com/username/manifest";
227233
manifestInfo = extractManifestRepositoryInformation(config);
234+
228235
expect(manifestInfo).toBeDefined();
229-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
230-
expect(manifestInfo!.githubUsername).toBe("username");
231-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
232-
expect(manifestInfo!.manifestRepoName).toBe("manifest");
236+
if (manifestInfo) {
237+
expect(manifestInfo.githubUsername).toBe("username");
238+
expect(manifestInfo.manifestRepoName).toBe("manifest");
239+
}
233240

234241
logger.info("Verified that manifest repository extraction works");
235242
});

0 commit comments

Comments
 (0)