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

Commit 511399c

Browse files
authored
[HOUSEKEEPING] Resolved eslint errors/warning in deployment commands (#452)
1 parent ea8a656 commit 511399c

File tree

8 files changed

+367
-369
lines changed

8 files changed

+367
-369
lines changed

src/commands/deployment/create.test.ts

+48-56
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ describe("test execute function", () => {
6565
expect(exitFn.mock.calls).toEqual([[1]]);
6666
});
6767
it("[+ve]: with deployment table and p1 values", async () => {
68-
jest.spyOn(azure, "addSrcToACRPipeline").mockReturnValueOnce(
69-
Promise.resolve({
70-
PartitionKey: uuid(),
71-
RowKey: uuid(),
72-
commitId: uuid(),
73-
imageTag: uuid(),
74-
p1: uuid(),
75-
service: uuid(),
76-
})
77-
);
68+
jest.spyOn(azure, "addSrcToACRPipeline").mockResolvedValueOnce({
69+
PartitionKey: uuid(),
70+
RowKey: uuid(),
71+
commitId: uuid(),
72+
imageTag: uuid(),
73+
p1: uuid(),
74+
service: uuid(),
75+
});
7876
const exitFn = jest.fn();
7977

8078
const vals = getMockedValues(true);
@@ -90,7 +88,7 @@ describe("test execute function", () => {
9088
it("[-ve]: with deployment table and p1 values; addSrcToACRPipeline fails", async () => {
9189
jest
9290
.spyOn(azure, "addSrcToACRPipeline")
93-
.mockReturnValueOnce(Promise.reject());
91+
.mockRejectedValueOnce(Error("fake error"));
9492
const exitFn = jest.fn();
9593

9694
const vals = getMockedValues(true);
@@ -112,19 +110,17 @@ describe("test execute function", () => {
112110
expect(exitFn.mock.calls).toEqual([[1]]);
113111
});
114112
it("[+ve]: with deployment table and p2 values", async () => {
115-
jest.spyOn(azure, "updateACRToHLDPipeline").mockReturnValueOnce(
116-
Promise.resolve({
117-
PartitionKey: uuid(),
118-
RowKey: uuid(),
119-
commitId: uuid(),
120-
env: uuid(),
121-
hldCommitId: uuid(),
122-
imageTag: uuid(),
123-
p1: uuid(),
124-
p2: uuid(),
125-
service: uuid(),
126-
})
127-
);
113+
jest.spyOn(azure, "updateACRToHLDPipeline").mockResolvedValueOnce({
114+
PartitionKey: uuid(),
115+
RowKey: uuid(),
116+
commitId: uuid(),
117+
env: uuid(),
118+
hldCommitId: uuid(),
119+
imageTag: uuid(),
120+
p1: uuid(),
121+
p2: uuid(),
122+
service: uuid(),
123+
});
128124
const exitFn = jest.fn();
129125

130126
const vals = getMockedValues(true);
@@ -140,7 +136,7 @@ describe("test execute function", () => {
140136
it("[-ve]: with deployment table and p2 values; updateACRToHLDPipeline fails", async () => {
141137
jest
142138
.spyOn(azure, "updateACRToHLDPipeline")
143-
.mockReturnValueOnce(Promise.reject());
139+
.mockRejectedValueOnce(Error("fake error"));
144140
const exitFn = jest.fn();
145141

146142
const vals = getMockedValues(true);
@@ -154,20 +150,18 @@ describe("test execute function", () => {
154150
expect(exitFn.mock.calls).toEqual([[1]]);
155151
});
156152
it("[+ve]: with deployment table and p3 values and hldCommitId values", async () => {
157-
jest.spyOn(azure, "updateHLDToManifestPipeline").mockReturnValueOnce(
158-
Promise.resolve({
159-
PartitionKey: uuid(),
160-
RowKey: uuid(),
161-
commitId: uuid(),
162-
env: uuid(),
163-
hldCommitId: uuid(),
164-
imageTag: uuid(),
165-
p1: uuid(),
166-
p2: uuid(),
167-
p3: uuid(),
168-
service: uuid(),
169-
})
170-
);
153+
jest.spyOn(azure, "updateHLDToManifestPipeline").mockResolvedValueOnce({
154+
PartitionKey: uuid(),
155+
RowKey: uuid(),
156+
commitId: uuid(),
157+
env: uuid(),
158+
hldCommitId: uuid(),
159+
imageTag: uuid(),
160+
p1: uuid(),
161+
p2: uuid(),
162+
p3: uuid(),
163+
service: uuid(),
164+
});
171165
const exitFn = jest.fn();
172166

173167
const vals = getMockedValues(true);
@@ -181,7 +175,7 @@ describe("test execute function", () => {
181175
it("[-ve]: with deployment table and p3 values; updateHLDToManifestPipeline fails", async () => {
182176
jest
183177
.spyOn(azure, "updateHLDToManifestPipeline")
184-
.mockReturnValueOnce(Promise.reject());
178+
.mockRejectedValueOnce(Error("fake error"));
185179
const exitFn = jest.fn();
186180

187181
const vals = getMockedValues(true);
@@ -193,21 +187,19 @@ describe("test execute function", () => {
193187
expect(exitFn.mock.calls).toEqual([[1]]);
194188
});
195189
it("[+ve]: with deployment table and p3 values and manifestCommitId values", async () => {
196-
jest.spyOn(azure, "updateManifestCommitId").mockReturnValueOnce(
197-
Promise.resolve({
198-
PartitionKey: uuid(),
199-
RowKey: uuid(),
200-
commitId: uuid(),
201-
env: uuid(),
202-
hldCommitId: uuid(),
203-
imageTag: uuid(),
204-
manifestCommitId: uuid(),
205-
p1: uuid(),
206-
p2: uuid(),
207-
p3: uuid(),
208-
service: uuid(),
209-
})
210-
);
190+
jest.spyOn(azure, "updateManifestCommitId").mockResolvedValueOnce({
191+
PartitionKey: uuid(),
192+
RowKey: uuid(),
193+
commitId: uuid(),
194+
env: uuid(),
195+
hldCommitId: uuid(),
196+
imageTag: uuid(),
197+
manifestCommitId: uuid(),
198+
p1: uuid(),
199+
p2: uuid(),
200+
p3: uuid(),
201+
service: uuid(),
202+
});
211203
const exitFn = jest.fn();
212204

213205
const vals = getMockedValues(true);
@@ -221,7 +213,7 @@ describe("test execute function", () => {
221213
it("[-ve]: with deployment table and p3 values; updateHLDToManifestPipeline fails", async () => {
222214
jest
223215
.spyOn(azure, "updateManifestCommitId")
224-
.mockReturnValueOnce(Promise.reject());
216+
.mockRejectedValueOnce(Error("fake error"));
225217
const exitFn = jest.fn();
226218

227219
const vals = getMockedValues(true);

src/commands/deployment/create.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ export interface CommandOptions {
3232
repository: string | undefined;
3333
}
3434

35+
export interface CreateConfig {
36+
accessKey: string;
37+
name: string;
38+
partitionKey: string;
39+
tableName: string;
40+
}
41+
3542
/**
3643
* Validates that the required values are provided.
3744
*
3845
* @param opts values from commander
3946
*/
40-
export const validateValues = (opts: CommandOptions): void => {
47+
export const validateValues = (opts: CommandOptions): CreateConfig => {
4148
if (
4249
!hasValue(opts.accessKey) ||
4350
!hasValue(opts.name) ||
@@ -48,13 +55,21 @@ export const validateValues = (opts: CommandOptions): void => {
4855
"Access key, storage account name, partition key and/or table name are not provided"
4956
);
5057
}
58+
59+
return {
60+
accessKey: opts.accessKey,
61+
name: opts.name,
62+
partitionKey: opts.partitionKey,
63+
tableName: opts.tableName,
64+
};
5165
};
5266

5367
export const handlePipeline1 = async (
5468
tableInfo: DeploymentTable,
5569
opts: CommandOptions
5670
): Promise<void> => {
5771
if (
72+
!opts.p1 ||
5873
!hasValue(opts.imageTag) ||
5974
!hasValue(opts.commitId) ||
6075
!hasValue(opts.service)
@@ -65,8 +80,7 @@ export const handlePipeline1 = async (
6580
}
6681
await addSrcToACRPipeline(
6782
tableInfo,
68-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69-
opts.p1!,
83+
opts.p1,
7084
opts.imageTag,
7185
opts.service,
7286
opts.commitId,
@@ -79,6 +93,7 @@ export const handlePipeline2 = async (
7993
opts: CommandOptions
8094
): Promise<void> => {
8195
if (
96+
!opts.p2 ||
8297
!hasValue(opts.hldCommitId) ||
8398
!hasValue(opts.env) ||
8499
!hasValue(opts.imageTag)
@@ -89,8 +104,7 @@ export const handlePipeline2 = async (
89104
}
90105
await updateACRToHLDPipeline(
91106
tableInfo,
92-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
93-
opts.p2!,
107+
opts.p2,
94108
opts.imageTag,
95109
opts.hldCommitId,
96110
opts.env,
@@ -111,17 +125,13 @@ export const execute = async (
111125
exitFn: (status: number) => Promise<void>
112126
): Promise<void> => {
113127
try {
114-
validateValues(opts);
128+
const config = validateValues(opts);
115129

116130
const tableInfo: DeploymentTable = {
117-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118-
accountKey: opts.accessKey!,
119-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120-
accountName: opts.name!,
121-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122-
partitionKey: opts.partitionKey!,
123-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
124-
tableName: opts.tableName!,
131+
accountKey: config.accessKey,
132+
accountName: config.name,
133+
partitionKey: config.partitionKey,
134+
tableName: config.tableName,
125135
};
126136

127137
if (hasValue(opts.p1)) {
@@ -131,10 +141,8 @@ export const execute = async (
131141
} else if (hasValue(opts.p3) && hasValue(opts.hldCommitId)) {
132142
await updateHLDToManifestPipeline(
133143
tableInfo,
134-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
135-
opts.hldCommitId!,
136-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137-
opts.p3!,
144+
opts.hldCommitId,
145+
opts.p3,
138146
opts.manifestCommitId,
139147
opts.pr,
140148
opts.repository

src/commands/deployment/dashboard.test.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,29 @@ afterAll(() => {
4444
disableVerboseLogging();
4545
});
4646

47-
const mockConfig = (): void => {
48-
(Config as jest.Mock).mockReturnValueOnce({
49-
azure_devops: {
50-
access_token: uuid(),
51-
org: uuid(),
52-
project: uuid(),
47+
const mockedConf = {
48+
azure_devops: {
49+
access_token: uuid(),
50+
org: uuid(),
51+
project: uuid(),
52+
},
53+
introspection: {
54+
dashboard: {
55+
image: "mcr.microsoft.com/k8s/bedrock/spektate:latest",
56+
name: "spektate",
5357
},
54-
introspection: {
55-
dashboard: {
56-
image: "mcr.microsoft.com/k8s/bedrock/spektate:latest",
57-
name: "spektate",
58-
},
59-
azure: {
60-
account_name: uuid(),
61-
key: uuid(),
62-
partition_key: uuid(),
63-
source_repo_access_token: "test_token",
64-
table_name: uuid(),
65-
},
58+
azure: {
59+
account_name: uuid(),
60+
key: uuid(),
61+
partition_key: uuid(),
62+
source_repo_access_token: "test_token",
63+
table_name: uuid(),
6664
},
67-
});
65+
},
66+
};
67+
68+
const mockConfig = (): void => {
69+
(Config as jest.Mock).mockReturnValueOnce(mockedConf);
6870
};
6971

7072
describe("Test validateValues function", () => {
@@ -196,14 +198,9 @@ describe("Validate dashboard clean up", () => {
196198

197199
describe("Fallback to azure devops access token", () => {
198200
test("Has repo_access_token specified", async () => {
199-
mockConfig();
200-
const config = Config();
201201
const envVars = (await getEnvVars(dashboardConf)).toString();
202202
logger.info(
203-
`spin: ${envVars}, act: ${
204-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
205-
config.introspection!.azure!.source_repo_access_token
206-
}`
203+
`spin: ${envVars}, act: ${mockedConf.introspection.azure.source_repo_access_token}`
207204
);
208205
const expectedSubstring = "REACT_APP_SOURCE_REPO_ACCESS_TOKEN=test_token";
209206
expect(envVars.includes(expectedSubstring)).toBeTruthy();
@@ -224,6 +221,7 @@ describe("Extract manifest repository information", () => {
224221

225222
let manifestInfo = extractManifestRepositoryInformation(config);
226223
expect(manifestInfo).toBeDefined();
224+
227225
if (manifestInfo) {
228226
expect(manifestInfo.githubUsername).toBeUndefined();
229227
expect(manifestInfo.manifestRepoName).toBe("materialized");

0 commit comments

Comments
 (0)