Skip to content

Commit

Permalink
fix: Added case handling for loadFromFile() functions that introduc…
Browse files Browse the repository at this point in the history
…e generated variables in ARM JSON files (#1917)

## Description

- When using a Bicep function like `loadFileAsBase64()` or
`loadFromJson`, the compiled ARM template contains a generated variable
with a name like `$fxv#1` or `$fxv#2`
- This variable currently fails the Pester test 'Variable names should
be camel-cased'
- This PR updates the test by
  - Adding support for the aforementioned deterministic variable name
- Updating the test to return the incorrect variables as opposed to just
claim that there's at least one incorrect variable

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FloadFromJson&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml)
|
|
[![avm.res.storage.storage-account](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.storage.storage-account.yml/badge.svg?branch=users%2Falsehr%2FloadFromJson&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.storage.storage-account.yml)
(Pester passed) |

## Type of Change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] Update to CI Environment or utlities (Non-module effecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored May 13, 2024
1 parent 25b6908 commit f859bf2
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,17 @@ Describe 'Module tests' -Tag 'Module' {
return
}

$CamelCasingFlag = @()
$Variable = $templateFileContent.variables.Keys

foreach ($Variab in $Variable) {
if ($Variab.substring(0, 1) -cnotmatch '[a-z]' -or $Variab -match '-') {
$CamelCasingFlag += $false
} else {
$CamelCasingFlag += $true
$incorrectVariables = @()
$Variables = $templateFileContent.variables.Keys

foreach ($variable in $Variables) {
# ^[a-z]+[a-zA-Z]+$ = starts with lower-case letter & may have uppercase letter later
# ^\$fxv#[0-9]+$ = starts with [$fxv#] & ends with a number. This function value is created as a variable when using a Bicep function like loadFileAsBase64() or loadFromJson()
if ($variable -cnotmatch '^[a-z]+[a-zA-Z]+$|^\$fxv#[0-9]+$' -or $variable -match '-') {
$incorrectVariables += $variable
}
}
$CamelCasingFlag | Should -Not -Contain $false
$incorrectVariables | Should -BeNullOrEmpty
}
}

Expand Down

0 comments on commit f859bf2

Please sign in to comment.