Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

fix: Exit process when error logging into Azure #192

Merged
merged 2 commits into from
Jul 9, 2019
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
10 changes: 6 additions & 4 deletions src/plugins/login/loginPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ describe("Login Plugin", () => {
expect(sls.variables["subscriptionId"]).toEqual("azureSubId");
});

it("logs an error from authentication", async () => {
it("logs an error from authentication and exits process", async () => {
unsetServicePrincipalEnvVariables();
process.exit = jest.fn() as any;
const errorMessage = "This is my error message";
AzureLoginService.interactiveLogin = jest.fn(() => {
throw new Error(errorMessage);
});
});
const sls = MockFactory.createTestServerless();
await invokeLoginHook(false, sls);
expect(AzureLoginService.interactiveLogin).toBeCalled()
expect(AzureLoginService.servicePrincipalLogin).not.toBeCalled();
expect(sls.cli.log).lastCalledWith(`Error: ${errorMessage}`)
expect(sls.cli.log).lastCalledWith(`Error: ${errorMessage}`);
expect(process.exit).toBeCalledWith(0);
});
})
});
1 change: 1 addition & 0 deletions src/plugins/login/loginPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class AzureLoginPlugin {
catch (e) {
this.serverless.cli.log("Error logging into azure");
this.serverless.cli.log(`${e}`);
process.exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test to validate this behavior?

}
}
}