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

Commit 3691a3f

Browse files
pjlittletbarlow12
authored andcommitted
fix: api uses shortened region names (#211)
When generating an APIM resource name, the service now uses the shortened resource name, consistent with other resources.
1 parent e503148 commit 3691a3f

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-azure-functions",
3-
"version": "1.0.0-6",
3+
"version": "1.0.0-7",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Azure Functions.",
55
"license": "MIT",
66
"main": "./lib/index.js",

src/services/apimService.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
OperationContract,
2020
ApiPolicyCreateOrUpdateResponse,
2121
} from "@azure/arm-apimanagement/esm/models";
22+
import { Utils } from "../shared/utils";
2223

2324
describe("APIM Service", () => {
2425
const apimConfig = MockFactory.createTestApimConfig();
@@ -46,7 +47,6 @@ describe("APIM Service", () => {
4647
subscriptionId: "ABC123",
4748
};
4849
});
49-
5050
it("is defined", () => {
5151
expect(ApimService).toBeDefined();
5252
});
@@ -56,6 +56,16 @@ describe("APIM Service", () => {
5656
expect(service).not.toBeNull();
5757
});
5858

59+
it("when generated, has a shorted region name in the resource name", () => {
60+
// if APIM name is ommited, it should auto-generate one that contains a shortened region name
61+
const apimConfigName = MockFactory.createTestApimConfig(true);
62+
(serverless.service.provider as any).apim = apimConfigName;
63+
64+
const service = new ApimService(serverless);
65+
const expectedRegionName = Utils.createShortAzureRegionName(service.getRegion());
66+
expect(apimConfigName.name.includes(expectedRegionName)).toBeTruthy();
67+
});
68+
5969
describe("Get service reference", () => {
6070
it("returns null when service doesn't exist", async () => {
6171
axios.request = jest.fn((requestConfig) => MockFactory.createTestAxiosResponse(requestConfig, apimGetService404, 404));

src/services/apimService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "@azure/arm-apimanagement/esm/models";
1111
import { Site } from "@azure/arm-appservice/esm/models";
1212
import { Guard } from "../shared/guard";
13+
import { ApimResource } from "../armTemplates/resources/apim";
1314

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

3031
if (!this.apimConfig.name) {
31-
this.apimConfig.name = `${this.config.provider.prefix}-${this.config.provider.region}-${this.config.provider.stage}-apim`
32+
this.apimConfig.name = ApimResource.getResourceName(this.config);
3233
}
3334

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

326327
return xml(policy, { indent: "\t" });
327328
}
328-
}
329+
}

src/test/mockFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ export class MockFactory {
267267
return (asYaml) ? yaml.dump(data) : data;
268268
}
269269

270-
public static createTestApimConfig(): ApiManagementConfig {
270+
public static createTestApimConfig(generateName: boolean = false): ApiManagementConfig {
271271
return {
272-
name: "test-apim-resource",
272+
name: generateName ? null : "test-apim-resource",
273273
api: {
274274
name: "test-apim-api1",
275275
subscriptionRequired: false,

0 commit comments

Comments
 (0)