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

Commit ad9b34d

Browse files
authored
[FIX] Issue 993: spk deployment get function is broken (missing await and --watch terminates) (#302)
1 parent 7115d5d commit ad9b34d

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/commands/deployment/get.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,15 @@ describe("Test execute function", () => {
195195
jest
196196
.spyOn(get, "initialize")
197197
.mockReturnValueOnce(Promise.resolve(initObject));
198-
jest.spyOn(get, "watchGetDeployments").mockReturnValueOnce();
198+
jest
199+
.spyOn(get, "watchGetDeployments")
200+
.mockReturnValueOnce(Promise.resolve());
199201
const exitFn = jest.fn();
200202

201203
const mockedVals = getMockedInputValues();
202204
mockedVals.watch = true;
203205
await execute(mockedVals, exitFn);
204-
expect(exitFn).toBeCalledTimes(1);
205-
expect(exitFn.mock.calls).toEqual([[0]]);
206+
expect(exitFn).toBeCalledTimes(0);
206207
});
207208
it("negative test", async () => {
208209
jest.spyOn(get, "initialize").mockReturnValueOnce(Promise.reject("Error"));
@@ -265,7 +266,7 @@ describe("Watch get deployments", () => {
265266
const values = getMockedValues();
266267
values.outputFormat = OUTPUT_FORMAT.WIDE;
267268

268-
watchGetDeployments(initObject, values);
269+
await watchGetDeployments(initObject, values);
269270
expect(getDeployments).toBeCalled();
270271
jest.advanceTimersByTime(6000);
271272
expect(getDeployments).toBeCalledTimes(2);

src/commands/deployment/get.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export const execute = async (
106106
const values = validateValues(opts);
107107
const initObjects = await initialize();
108108
if (opts.watch) {
109-
watchGetDeployments(initObjects, values);
109+
await watchGetDeployments(initObjects, values);
110110
} else {
111-
getDeployments(initObjects, values);
111+
await getDeployments(initObjects, values);
112+
await exitFn(0);
112113
}
113-
await exitFn(0);
114114
} catch (err) {
115115
logger.error(`Error occurred while getting deployment(s)`);
116116
logger.error(err);
@@ -218,9 +218,14 @@ export const getClusterSyncStatuses = (
218218
manifestUrlSplit[6],
219219
config.azure_devops.access_token
220220
);
221-
manifestRepo.getManifestSyncState().then((syncCommits: ITag[]) => {
222-
resolve(syncCommits);
223-
});
221+
manifestRepo
222+
.getManifestSyncState()
223+
.then((syncCommits: ITag[]) => {
224+
resolve(syncCommits);
225+
})
226+
.catch(e => {
227+
reject(e);
228+
});
224229
} else if (
225230
config.azure_devops?.manifest_repository &&
226231
config.azure_devops?.manifest_repository.includes("github.com")
@@ -233,9 +238,14 @@ export const getClusterSyncStatuses = (
233238
manifestUrlSplit[4],
234239
config.azure_devops.access_token
235240
);
236-
manifestRepo.getManifestSyncState().then((syncCommits: ITag[]) => {
237-
resolve(syncCommits);
238-
});
241+
manifestRepo
242+
.getManifestSyncState()
243+
.then((syncCommits: ITag[]) => {
244+
resolve(syncCommits);
245+
})
246+
.catch(e => {
247+
reject(e);
248+
});
239249
} else {
240250
resolve();
241251
}
@@ -300,17 +310,17 @@ export const initialize = async (): Promise<IInitObject> => {
300310
* @param initObject Initialization Object
301311
* @param values Validated values from commander
302312
*/
303-
export const watchGetDeployments = (
313+
export const watchGetDeployments = async (
304314
initObjects: IInitObject,
305315
values: IValidatedOptions
306316
) => {
307317
const timeInterval = 5000;
308318

309319
// Call get deployments once, and then set the timer.
310-
getDeployments(initObjects, values);
320+
await getDeployments(initObjects, values);
311321

312-
setInterval(() => {
313-
getDeployments(initObjects, values);
322+
setInterval(async () => {
323+
await getDeployments(initObjects, values);
314324
}, timeInterval);
315325
};
316326

0 commit comments

Comments
 (0)