Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
589 additions
and
278 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { MockFactory } from "../../test/mockFactory"; | ||
import { invokeHook } from "../../test/utils"; | ||
import { AzureApimFunctionPlugin } from './apimFunctionPlugin'; | ||
|
||
jest.mock('../../services/apimService'); | ||
import { ApimService } from '../../services/apimService'; | ||
|
||
describe('APIM Function Plugin', () => { | ||
it('calls deploy function', async () => { | ||
const deployFunction = jest.fn(); | ||
|
||
ApimService.prototype.deployFunction = deployFunction; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
sls.service.provider['apim'] = 'apim config' | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureApimFunctionPlugin(sls, options); | ||
|
||
await invokeHook(plugin, 'after:deploy:function:deploy'); | ||
|
||
expect(sls.cli.log).toBeCalledWith('Starting APIM function deployment') | ||
expect(deployFunction).toBeCalled(); | ||
expect(sls.cli.log).lastCalledWith('Finished APIM function deployment') | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { MockFactory } from "../../test/mockFactory"; | ||
import { invokeHook } from "../../test/utils"; | ||
import { AzureDeployPlugin } from "./azureDeployPlugin"; | ||
|
||
jest.mock("../../services/functionAppService"); | ||
import { FunctionAppService } from "../../services/functionAppService"; | ||
|
||
jest.mock("../../services/resourceService"); | ||
import { ResourceService } from "../../services/resourceService"; | ||
|
||
describe('Deploy plugin', () => { | ||
|
||
it('calls deploy hook', async () => { | ||
const deployResourceGroup = jest.fn(); | ||
const functionAppStub = "Function App Stub"; | ||
const deploy = jest.fn(() => Promise.resolve(functionAppStub)); | ||
const uploadFunctions = jest.fn(); | ||
|
||
ResourceService.prototype.deployResourceGroup = deployResourceGroup | ||
FunctionAppService.prototype.deploy = deploy | ||
FunctionAppService.prototype.uploadFunctions = uploadFunctions | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureDeployPlugin(sls, options); | ||
|
||
await invokeHook(plugin, 'deploy:deploy'); | ||
|
||
expect(deployResourceGroup).toBeCalled(); | ||
expect(deploy).toBeCalled(); | ||
expect(uploadFunctions).toBeCalledWith(functionAppStub); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { MockFactory } from "../../test/mockFactory"; | ||
import { invokeHook } from "../../test/utils"; | ||
import { AzureLoginPlugin } from "./loginPlugin"; | ||
import { AzureLoginService } from "../../services/loginService"; | ||
|
||
describe('Login Plugin', () => { | ||
|
||
const authResponse = MockFactory.createTestAuthResponse(); | ||
|
||
it('returns if azure credentials are set', async () => { | ||
const interactiveLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
const servicePrincipalLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
|
||
AzureLoginService.interactiveLogin = interactiveLogin; | ||
AzureLoginService.servicePrincipalLogin = servicePrincipalLogin; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
sls.variables['azureCredentials'] = 'credentials'; | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureLoginPlugin(sls, options); | ||
|
||
await invokeHook(plugin, 'before:package:initialize'); | ||
|
||
expect(interactiveLogin).not.toBeCalled(); | ||
expect(servicePrincipalLogin).not.toBeCalled(); | ||
}); | ||
|
||
it('calls login if azure credentials are not set', async () => { | ||
const interactiveLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
const servicePrincipalLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
|
||
AzureLoginService.interactiveLogin = interactiveLogin; | ||
AzureLoginService.servicePrincipalLogin = servicePrincipalLogin; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureLoginPlugin(sls, options); | ||
|
||
await invokeHook(plugin, 'before:package:initialize'); | ||
|
||
expect(interactiveLogin).toBeCalled(); | ||
expect(servicePrincipalLogin).not.toBeCalled(); | ||
}); | ||
|
||
it('calls service principal login if environment variables are set', async () => { | ||
|
||
process.env.azureSubId = 'azureSubId'; | ||
process.env.azureServicePrincipalClientId = 'azureServicePrincipalClientId'; | ||
process.env.azureServicePrincipalPassword = 'azureServicePrincipalPassword'; | ||
process.env.azureServicePrincipalTenantId = 'azureServicePrincipalTenantId'; | ||
|
||
const interactiveLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
const servicePrincipalLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
|
||
AzureLoginService.interactiveLogin = interactiveLogin; | ||
AzureLoginService.servicePrincipalLogin = servicePrincipalLogin; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureLoginPlugin(sls, options); | ||
await invokeHook(plugin, 'before:package:initialize'); | ||
expect(servicePrincipalLogin).toBeCalledWith( | ||
'azureServicePrincipalClientId', | ||
'azureServicePrincipalPassword', | ||
'azureServicePrincipalTenantId' | ||
) | ||
expect(interactiveLogin).not.toBeCalled(); | ||
|
||
expect(sls.variables['azureCredentials']).toEqual(authResponse.credentials); | ||
expect(sls.variables['subscriptionId']).toEqual('azureSubId'); | ||
}); | ||
|
||
it('calls interactive login if environment variables are not set', async () => { | ||
delete process.env.azureSubId; | ||
delete process.env.azureServicePrincipalClientId; | ||
delete process.env.azureServicePrincipalPassword; | ||
delete process.env.azureServicePrincipalTenantId; | ||
|
||
const interactiveLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
const servicePrincipalLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
|
||
AzureLoginService.interactiveLogin = interactiveLogin; | ||
AzureLoginService.servicePrincipalLogin = servicePrincipalLogin; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureLoginPlugin(sls, options); | ||
await invokeHook(plugin, 'before:package:initialize'); | ||
expect(servicePrincipalLogin).not.toBeCalled(); | ||
expect(interactiveLogin).toBeCalled(); | ||
|
||
expect(sls.variables['azureCredentials']).toEqual(authResponse.credentials); | ||
expect(sls.variables['subscriptionId']).toEqual('azureSubId'); | ||
}); | ||
|
||
it('logs an error from authentication', async () => { | ||
process.env.azureSubId = 'azureSubId'; | ||
process.env.azureServicePrincipalClientId = 'azureServicePrincipalClientId'; | ||
process.env.azureServicePrincipalPassword = 'azureServicePrincipalPassword'; | ||
process.env.azureServicePrincipalTenantId = 'azureServicePrincipalTenantId'; | ||
|
||
const interactiveLogin = jest.fn(() => Promise.resolve(authResponse)); | ||
const errorMessage = 'This is my error message'; | ||
const servicePrincipalLogin = jest.fn(() => { | ||
throw new Error(errorMessage); | ||
}); | ||
|
||
AzureLoginService.interactiveLogin = interactiveLogin; | ||
AzureLoginService.servicePrincipalLogin = servicePrincipalLogin; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureLoginPlugin(sls, options); | ||
await invokeHook(plugin, 'before:package:initialize'); | ||
expect(servicePrincipalLogin).toBeCalledWith( | ||
'azureServicePrincipalClientId', | ||
'azureServicePrincipalPassword', | ||
'azureServicePrincipalTenantId' | ||
) | ||
expect(interactiveLogin).not.toBeCalled(); | ||
expect(sls.cli.log).lastCalledWith(`Error: ${errorMessage}`) | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { MockFactory } from "../../test/mockFactory"; | ||
import { invokeHook } from "../../test/utils"; | ||
import { AzurePackage } from "./azurePackage" | ||
|
||
jest.mock('../../shared/bindings'); | ||
import { BindingUtils } from '../../shared/bindings'; | ||
jest.mock('../../shared/utils'); | ||
import { Utils, FunctionMetadata } from '../../shared/utils'; | ||
|
||
describe('Azure Package Plugin', () => { | ||
it('sets up provider configuration', async () => { | ||
const metadata = 'metadata'; | ||
const functionName = 'function1'; | ||
|
||
const getFunctionMetaDataFn = jest.fn(() => metadata as any as FunctionMetadata); | ||
const createEventsBindingsFn = jest.fn(); | ||
|
||
Utils.getFunctionMetaData = getFunctionMetaDataFn | ||
BindingUtils.createEventsBindings = createEventsBindingsFn | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzurePackage(sls, options); | ||
|
||
await invokeHook(plugin, 'package:setupProviderConfiguration'); | ||
|
||
expect(sls.cli.log).toBeCalledWith('Building Azure Events Hooks'); | ||
expect(getFunctionMetaDataFn).toBeCalledWith(functionName, sls); | ||
expect(createEventsBindingsFn).toBeCalledWith(sls.config.servicePath, functionName, metadata); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MockFactory } from "../../test/mockFactory"; | ||
import { invokeHook } from "../../test/utils"; | ||
import { AzureRemove } from "./azureRemove"; | ||
|
||
jest.mock("../../services/resourceService"); | ||
import { ResourceService } from "../../services/resourceService"; | ||
|
||
describe('Remove Plugin', () => { | ||
it('calls remove hook', async () => { | ||
const deleteDeployment = jest.fn(); | ||
const deleteResourceGroup = jest.fn(); | ||
|
||
ResourceService.prototype.deleteDeployment = deleteDeployment; | ||
ResourceService.prototype.deleteResourceGroup = deleteResourceGroup; | ||
|
||
const sls = MockFactory.createTestServerless(); | ||
const options = MockFactory.createTestServerlessOptions(); | ||
const plugin = new AzureRemove(sls, options); | ||
|
||
await invokeHook(plugin, 'remove:remove'); | ||
|
||
expect(deleteDeployment).toBeCalled(); | ||
expect(deleteResourceGroup).toBeCalled(); | ||
expect(sls.cli.log).toBeCalledWith('Service successfully removed'); | ||
}); | ||
}); |
Oops, something went wrong.