Skip to content

Commit

Permalink
fix: Throw error if user tries to specify function for deployment (#262)
Browse files Browse the repository at this point in the history
Azure Functions does not support deployments of individual functions. This throws an error if a user tries to target an individual function for deployment or deployment list.

Resolves #258
  • Loading branch information
tbarlow12 committed Aug 27, 2019
1 parent b1a7c72 commit 9b2257d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/plugins/deploy/azureDeployPlugin.test.ts
Expand Up @@ -57,14 +57,28 @@ describe("Deploy plugin", () => {
expect(uploadFunctions).toBeCalledWith(functionAppStub);
});

it("Crashes deploy if function is specified", async () => {
plugin = new AzureDeployPlugin(sls, { function: "myFunction" } as any);
await expect(invokeHook(plugin, "deploy:deploy"))
.rejects.toThrow("The Azure Functions plugin does not currently support deployments of individual functions. " +
"Azure Functions are zipped up as a package and deployed together as a unit");
});

it("lists deployments", async () => {
const deploymentString = "deployments";
ResourceService.prototype.listDeployments = jest.fn(() => Promise.resolve(deploymentString));
await invokeHook(plugin, "deploy:list:list");
expect(ResourceService.prototype.listDeployments).toBeCalled();
expect(sls.cli.log).lastCalledWith(deploymentString);
});


it("Crashes deploy list if function is specified", async () => {
plugin = new AzureDeployPlugin(sls, { function: "myFunction" } as any);
await expect(invokeHook(plugin, "deploy:list:list"))
.rejects.toThrow("The Azure Functions plugin does not currently support deployments of individual functions. " +
"Azure Functions are zipped up as a package and deployed together as a unit");
});

it("crashes deploy if zip file is not found", async () => {
FunctionAppService.prototype.getFunctionZipFile = jest.fn(() => "notExisting.zip");
await expect(invokeHook(plugin, "deploy:deploy"))
Expand Down
21 changes: 21 additions & 0 deletions src/plugins/deploy/azureDeployPlugin.ts
Expand Up @@ -42,6 +42,10 @@ export class AzureDeployPlugin extends AzureBasePlugin<AzureLoginOptions> {
usage: "Sets the Azure subscription ID",
shortcut: "i",
},
function: {
usage: "Deployment of individual function - NOT SUPPORTED",
shortcut: "f",
}
}
},
options: {
Expand All @@ -64,19 +68,25 @@ export class AzureDeployPlugin extends AzureBasePlugin<AzureLoginOptions> {
package: {
usage: "Package to deploy",
shortcut: "p",
},
function: {
usage: "Deployment of individual function - NOT SUPPORTED",
shortcut: "f",
}
}
}
}
}

private async list() {
this.checkForIndividualFunctionDeploy();
this.log("Listing deployments");
const resourceService = new ResourceService(this.serverless, this.options);
this.log(await resourceService.listDeployments());
}

private async deploy() {
this.checkForIndividualFunctionDeploy();
const resourceService = new ResourceService(this.serverless, this.options);
const functionAppService = new FunctionAppService(this.serverless, this.options);
const zipFile = functionAppService.getFunctionZipFile();
Expand All @@ -87,4 +97,15 @@ export class AzureDeployPlugin extends AzureBasePlugin<AzureLoginOptions> {
const functionApp = await functionAppService.deploy();
await functionAppService.uploadFunctions(functionApp);
}

/**
* Check to see if user tried to target an individual function for deployment or deployment list
* Throws error if `function` is specified
*/
private checkForIndividualFunctionDeploy() {
if (this.options.function) {
throw new Error("The Azure Functions plugin does not currently support deployments of individual functions. " +
"Azure Functions are zipped up as a package and deployed together as a unit");
}
}
}

0 comments on commit 9b2257d

Please sign in to comment.