-
Notifications
You must be signed in to change notification settings - Fork 456
The CI environment Static validation
This section provides an overview of the principles the static validation is built upon, how it is set up, and how you can interact with it.
All module Unit tests are performed with the help of Pester to ensure that the modules are configured correctly, documentation is up to date, and modules don't turn stale.
The following activities are performed by the utilities/pipelines/staticValidation/module.tests.ps1
script.
-
File/folder tests
-
General module folder tests
- Module should contain a [
main.json
&main.bicep
] file. - Module should contain a [
README.md
] file. - Module should contain a [
.test
] folder. - Module should contain a [
version.json
] file.
- Module should contain a [
-
.test folder
- Folder should contain one or more test files.
-
General module folder tests
-
Pipeline tests
- Module should have a GitHub workflow.
- Module workflow should have trigger for cross-module references, if any.
- Module should have an Azure DevOps pipeline.
- Module pipeline should have trigger for cross-module references, if any.
-
Module tests
-
Readme content tests
-
README.md
file should not be empty. -
Set-ModuleReadMe
script should not apply any updates.
-
-
Compiled ARM template tests
- Compiled ARM template should be latest.
-
General template tests
- The template file should not be empty.
- Template schema version should be the latest.
- Template schema should use HTTPS reference.
- All apiVersion properties should be set to a static, hard-coded value.
- The template file should contain required elements [schema], [contentVersion], [resources].
- If delete lock is implemented, the template should have a lock parameter with an empty default value.
- Parameter names should be camel-cased (no dashes or underscores and must start with lower-case letter).
- Variable names should be camel-cased (no dashes or underscores and must start with lower-case letter).
- Output names should be camel-cased (no dashes or underscores and must start with lower-case letter).
- CUA ID deployment should be present in the template.
- The Location should be defined as a parameter, with the default value of [resourceGroup().Location] or global for ResourceGroup deployment scope.
- Location output should be returned for resources that use it.
- Resource Group output should exist for resources that are deployed into a resource group scope.
- Resource name output should exist.
- Resource ID output should exist.
- All non-required parameters in template file should not have description that start with "Required.".
-
Metadata content tests
- template file should have a module name specified.
- template file should have a module description specified.
-
Readme content tests
-
Test file tests
-
General test file
- Bicep test deployment name should contain [
-test-
]. - Bicep test deployment should have parameter [
serviceShort
].
- Bicep test deployment name should contain [
-
Token usage
- [Tokens] Test file should not contain the plain value for token guid.
-
General test file
-
API version tests
- In used resource type should use one of the recent API version(s). Currently using .
In this phase, Pester analyzes the API version of each resource type deployed by the module.
In particular, each resource's API version is compared with those currently available on Azure. This test has a certain level of tolerance (does not enforce the latest version): the API version in use should be one of the 5 latest versions available (including preview versions) or one of the the 5 latest non-preview versions.
This test also leverages the utilities/pipelines/staticValidation/module.tests.ps1
script.
To test the API versions, the test leverages the file utilities/src/apiSpecsList.json
file as a reference for all API versions available for any used Provider Namespace & Resource Type.
NOTE: If this file does not exist, the API tests will be skipped.
NOTE: This functionality has a dependency on the AzureAPICrawler PowerShell module.
The pipeline platform.apiSpecs.yml
updates this file using the script utilities/tools/platform/Set-ApiSpecsFile.ps1
and, once registered, runs on a weekly schedule. Upon execution, the script installs & imports the AzureAPICrawler
module, fetches all available API versions for all Resource Types via the module and updates the JSON file according to the latest information.
This paragraph is intended for CARML contributors or more generally for those leveraging the CARML CI environment and having the need to update or add a new module to the library.
Refer to the below snippet to leverage the 'Test-ModuleLocally.ps1' script and verify if your module will comply to the static validation before pushing to source control.
#########[ Function Test-ModulesLocally.ps1 ]#############
$pathToRepository = '<pathToClonedRepo>'
. "$pathToRepository\utilities\tools\Test-ModuleLocally.ps1"
# REQUIRED INPUT FOR TESTING
$TestModuleLocallyInput = @{
templateFilePath = "$pathToRepository\modules\authorization\role-definition\main.bicep"
PesterTest = $true
DeploymentTest = $false
ValidationTest = $false
}
Test-ModuleLocally @TestModuleLocallyInput -Verbose
You can use the
Get-Help
cmdlet to show more options on how you can use this script.