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

Commit

Permalink
fix: api uses shortened region names (#211)
Browse files Browse the repository at this point in the history
When generating an APIM resource name, the service now
uses the shortened resource name, consistent with other resources.
  • Loading branch information
pjlittle authored and tbarlow12 committed Sep 13, 2019
1 parent e503148 commit 3691a3f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-azure-functions",
"version": "1.0.0-6",
"version": "1.0.0-7",
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Azure Functions.",
"license": "MIT",
"main": "./lib/index.js",
Expand Down
12 changes: 11 additions & 1 deletion src/services/apimService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
OperationContract,
ApiPolicyCreateOrUpdateResponse,
} from "@azure/arm-apimanagement/esm/models";
import { Utils } from "../shared/utils";

describe("APIM Service", () => {
const apimConfig = MockFactory.createTestApimConfig();
Expand Down Expand Up @@ -46,7 +47,6 @@ describe("APIM Service", () => {
subscriptionId: "ABC123",
};
});

it("is defined", () => {
expect(ApimService).toBeDefined();
});
Expand All @@ -56,6 +56,16 @@ describe("APIM Service", () => {
expect(service).not.toBeNull();
});

it("when generated, has a shorted region name in the resource name", () => {
// if APIM name is ommited, it should auto-generate one that contains a shortened region name
const apimConfigName = MockFactory.createTestApimConfig(true);
(serverless.service.provider as any).apim = apimConfigName;

const service = new ApimService(serverless);
const expectedRegionName = Utils.createShortAzureRegionName(service.getRegion());
expect(apimConfigName.name.includes(expectedRegionName)).toBeTruthy();
});

describe("Get service reference", () => {
it("returns null when service doesn't exist", async () => {
axios.request = jest.fn((requestConfig) => MockFactory.createTestAxiosResponse(requestConfig, apimGetService404, 404));
Expand Down
5 changes: 3 additions & 2 deletions src/services/apimService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@azure/arm-apimanagement/esm/models";
import { Site } from "@azure/arm-appservice/esm/models";
import { Guard } from "../shared/guard";
import { ApimResource } from "../armTemplates/resources/apim";

/**
* APIM Service handles deployment and integration with Azure API Management
Expand All @@ -28,7 +29,7 @@ export class ApimService extends BaseService {
}

if (!this.apimConfig.name) {
this.apimConfig.name = `${this.config.provider.prefix}-${this.config.provider.region}-${this.config.provider.stage}-apim`
this.apimConfig.name = ApimResource.getResourceName(this.config);
}

if (!this.apimConfig.backend) {
Expand Down Expand Up @@ -325,4 +326,4 @@ export class ApimService extends BaseService {

return xml(policy, { indent: "\t" });
}
}
}
4 changes: 2 additions & 2 deletions src/test/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ export class MockFactory {
return (asYaml) ? yaml.dump(data) : data;
}

public static createTestApimConfig(): ApiManagementConfig {
public static createTestApimConfig(generateName: boolean = false): ApiManagementConfig {
return {
name: "test-apim-resource",
name: generateName ? null : "test-apim-resource",
api: {
name: "test-apim-api1",
subscriptionRequired: false,
Expand Down

0 comments on commit 3691a3f

Please sign in to comment.