This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add resource group name hash to resource names (#310)
* Add hashed resource name to resource name * Fix tests * Fix resource group name test issues * Add test * Add naming service test * test: APIM resource test (#311) * Add test to validate resource naming * Add service options and refactor * Address pr feedback
- Loading branch information
Showing
17 changed files
with
526 additions
and
100 deletions.
There are no files selected for viewing
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,55 @@ | ||
import { ApimResource } from "./apim"; | ||
import { ServerlessAzureConfig } from "../../models/serverless"; | ||
import md5 from "md5"; | ||
import configConstants from "../../config"; | ||
|
||
describe("APIM Resource", () => { | ||
const resourceGroupName = "myResourceGroup"; | ||
const prefix = "prefix"; | ||
const region = "eastus2"; | ||
const stage = "prod"; | ||
|
||
it("generates the correct resource name", () => { | ||
const resourceGroupHash = md5(resourceGroupName).substr( | ||
0, | ||
configConstants.resourceGroupHashLength | ||
); | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(ApimResource.getResourceName(config)).toEqual( | ||
`${prefix}-eus2-${stage}-${resourceGroupHash}-apim` | ||
); | ||
}); | ||
|
||
it("uses the specified name from the azure provider", () => { | ||
const apimName = "myAPIM"; | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
apim: { | ||
name: apimName | ||
}, | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(ApimResource.getResourceName(config)).toEqual(apimName); | ||
}); | ||
}); |
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,55 @@ | ||
import { AppInsightsResource } from "./appInsights"; | ||
import { ServerlessAzureConfig } from "../../models/serverless"; | ||
import md5 from "md5"; | ||
import configConstants from "../../config"; | ||
|
||
describe("App Insights Resource", () => { | ||
const resourceGroupName = "myResourceGroup"; | ||
const prefix = "prefix"; | ||
const region = "eastus2"; | ||
const stage = "prod"; | ||
|
||
it("generates the correct resource name", () => { | ||
const resourceGroupHash = md5(resourceGroupName).substr( | ||
0, | ||
configConstants.resourceGroupHashLength | ||
); | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(AppInsightsResource.getResourceName(config)).toEqual( | ||
`${prefix}-eus2-${stage}-${resourceGroupHash}-appinsights` | ||
); | ||
}); | ||
|
||
it("uses the specified name from the azure provider", () => { | ||
const appInsightsName = "myAppInsights"; | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x", | ||
appInsights: { | ||
name: appInsightsName, | ||
}, | ||
}, | ||
service: "myapp", | ||
} as any; | ||
|
||
expect(AppInsightsResource.getResourceName(config)).toEqual(appInsightsName); | ||
}); | ||
}); |
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,55 @@ | ||
import { AppServicePlanResource } from "./appServicePlan"; | ||
import { ServerlessAzureConfig } from "../../models/serverless"; | ||
import md5 from "md5"; | ||
import configConstants from "../../config"; | ||
|
||
describe("App Service Plan Resource", () => { | ||
const resourceGroupName = "myResourceGroup"; | ||
const prefix = "prefix"; | ||
const region = "eastus2"; | ||
const stage = "prod"; | ||
|
||
it("generates the correct resource name", () => { | ||
const resourceGroupHash = md5(resourceGroupName).substr( | ||
0, | ||
configConstants.resourceGroupHashLength | ||
); | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(AppServicePlanResource.getResourceName(config)).toEqual( | ||
`${prefix}-eus2-${stage}-${resourceGroupHash}-asp` | ||
); | ||
}); | ||
|
||
it("uses the specified name from the azure provider", () => { | ||
const appServicePlanName = "myAppServicePlan"; | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x", | ||
appServicePlan: { | ||
name: appServicePlanName, | ||
}, | ||
}, | ||
service: "myapp", | ||
} as any; | ||
|
||
expect(AppServicePlanResource.getResourceName(config)).toEqual(appServicePlanName); | ||
}); | ||
}); |
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,51 @@ | ||
import { FunctionAppResource } from "./functionApp"; | ||
import { ServerlessAzureConfig } from "../../models/serverless"; | ||
|
||
describe("Function App Resource", () => { | ||
const resourceGroupName = "myResourceGroup"; | ||
const prefix = "prefix"; | ||
const region = "westus"; | ||
const stage = "prod"; | ||
|
||
it("generates the correct resource name", () => { | ||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(FunctionAppResource.getResourceName(config)).toEqual( | ||
`${config.provider.prefix}-wus-${config.provider.stage}` | ||
); | ||
}); | ||
|
||
it("uses the specified name from the azure provider", () => { | ||
const serviceName = "myapp"; | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
apim: { | ||
name: "" | ||
}, | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x", | ||
functionApp: { | ||
name: serviceName, | ||
}, | ||
}, | ||
service: serviceName | ||
} as any; | ||
|
||
expect(FunctionAppResource.getResourceName(config)).toEqual(serviceName); | ||
}); | ||
}); |
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,55 @@ | ||
import { HostingEnvironmentResource } from "./hostingEnvironment"; | ||
import { ServerlessAzureConfig } from "../../models/serverless"; | ||
import md5 from "md5"; | ||
import configConstants from "../../config"; | ||
|
||
describe("Azure Hosting Environment Resource", () => { | ||
const resourceGroupName = "myResourceGroup"; | ||
const prefix = "prefix"; | ||
const region = "eastus2"; | ||
const stage = "prod"; | ||
|
||
it("generates the correct resource name", () => { | ||
const resourceGroupHash = md5(resourceGroupName).substr( | ||
0, | ||
configConstants.resourceGroupHashLength | ||
); | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(HostingEnvironmentResource.getResourceName(config)).toEqual( | ||
`${prefix}-eus2-${stage}-${resourceGroupHash}-ase` | ||
); | ||
}); | ||
|
||
it("uses the specified name from the azure provider", () => { | ||
const hostingEnvironmentName = "myHostingEnv"; | ||
|
||
const config: ServerlessAzureConfig = { | ||
provider: { | ||
hostingEnvironment: { | ||
name: hostingEnvironmentName | ||
}, | ||
name: "azure", | ||
prefix, | ||
region, | ||
stage, | ||
resourceGroup: resourceGroupName, | ||
runtime: "nodejs10.x" | ||
}, | ||
service: "" | ||
} as any; | ||
|
||
expect(HostingEnvironmentResource.getResourceName(config)).toEqual(hostingEnvironmentName); | ||
}); | ||
}); |
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
Oops, something went wrong.