From f6f69bcd60f6b84333e96e6ba77f2414fc74fe05 Mon Sep 17 00:00:00 2001 From: Atharva Mulmuley Date: Thu, 3 Jun 2021 13:34:02 +0530 Subject: [PATCH] fix for promise --- __tests__/run.test.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/__tests__/run.test.ts b/__tests__/run.test.ts index 1d5d3e24..58e91cae 100644 --- a/__tests__/run.test.ts +++ b/__tests__/run.test.ts @@ -223,20 +223,21 @@ describe('Testing all functions.', () => { jest.spyOn(arc,'sleep').mockImplementation(); jest.spyOn(fs, 'chmodSync').mockImplementation(() => {}); jest.spyOn(core, 'exportVariable').mockImplementation(() => {}); - return arc.getArcKubeconfig().then(()=>{ - expect(core.getInput).toBeCalledTimes(4); - expect(io.which).toHaveBeenCalledWith("az",true); - expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(1,`account show`, false); - expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(2,`extension remove -n connectedk8s`, false); - expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(3,`extension add -n connectedk8s`, false); - expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(4,`extension list`, false); - expect(child_process.spawn).toHaveBeenCalledWith('az',['connectedk8s','proxy','-n','testcluster','-g','testrg','-f',path.join('tempDirPath', 'kubeconfig_1234561234567'),'--token','token'], { - detached: true, - stdio: 'ignore' - }); - expect(arc.sleep).toBeCalled(); - expect(fs.chmodSync).toHaveBeenCalledWith(path.join('tempDirPath', 'kubeconfig_1234561234567'), '600'); - expect(core.exportVariable).toHaveBeenCalledWith('KUBECONFIG', path.join('tempDirPath', 'kubeconfig_1234561234567')); + await arc.getArcKubeconfig().catch(ex => { + throw new Error('Error: Could not get the KUBECONFIG for arc cluster: ' + ex); }); + expect(core.getInput).toBeCalledTimes(4); + expect(io.which).toHaveBeenCalledWith("az",true); + expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(1,`account show`, false); + expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(2,`extension remove -n connectedk8s`, false); + expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(3,`extension add -n connectedk8s`, false); + expect(arc.executeAzCliCommand).toHaveBeenNthCalledWith(4,`extension list`, false); + expect(child_process.spawn).toHaveBeenCalledWith('az',['connectedk8s','proxy','-n','testcluster','-g','testrg','-f',path.join('tempDirPath', 'kubeconfig_1234561234567'),'--token','token'], { + detached: true, + stdio: 'ignore' + }); + expect(arc.sleep).toBeCalled(); + expect(fs.chmodSync).toHaveBeenCalledWith(path.join('tempDirPath', 'kubeconfig_1234561234567'), '600'); + expect(core.exportVariable).toHaveBeenCalledWith('KUBECONFIG', path.join('tempDirPath', 'kubeconfig_1234561234567')); }) });