Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ALZ management group suffix references #49

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/ALZ/Assets/alz-bicep-config/v0.14.1-pre.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,6 @@
"DefaultValue": "alz",
"Valid": "^[a-zA-Z]{3,5}$"
},
"Suffix": {
"Type": "UserInput",
"Description": "The suffix that will be added to all resources created by this deployment. (e.g. 'test')",
"Targets": [
{
"Name": "parTopLevelManagementGroupSuffix.value",
"Destination": "Parameters"
}
],
"Value": "",
"DefaultValue": "",
"Valid": "^[a-zA-Z]{0,5}$"
},
"Location": {
"Type": "UserInput",
"Description": "Deployment location. (e.g. 'uksouth')",
Expand Down
118 changes: 52 additions & 66 deletions src/Tests/Unit/Private/Edit-ALZConfigurationFilesInPlace.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ InModuleScope 'ALZ' {
[Parameter(Mandatory = $true)]
[string]$withValue
)
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Value = $withValue
Targets = @(
[pscustomobject]@{
Name = $configTarget
Destination = "Parameters"
})
}
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Value = $withValue
Targets = @(
[pscustomobject]@{
Name = $configTarget
Destination = "Parameters"
})
}
}

return $config
return $config
}

function Format-ExpectedResult {
Expand All @@ -69,7 +69,7 @@ InModuleScope 'ALZ' {
Context 'Edit-ALZConfigurationFilesInPlace should replace the parameters correctly' {

It 'Should replace array values correctly (JSON Object) - first' {
$config = Initialize-TestConfiguration -configTarget "parValue.value.[0]" -withValue "value"
$config = Initialize-TestConfiguration -configTarget "parValue.value.[0]" -withValue "value"

$fileContent = '{
"parameters": {
Expand Down Expand Up @@ -99,15 +99,15 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Should replace array an entire array correctly (JSON Object)' {
$config = Initialize-TestConfiguration -configTarget "parValue.value.[1]" -withValue "value"
$config = Initialize-TestConfiguration -configTarget "parValue.value.[1]" -withValue "value"

$fileContent = '{
"parameters": {
Expand Down Expand Up @@ -137,7 +137,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -147,7 +147,7 @@ InModuleScope 'ALZ' {
It 'Should replace array values correctly (JSON Object) - second' {

$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Value = @(
Expand Down Expand Up @@ -185,15 +185,15 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Should not write to files that havent been changed.' {
$config = Initialize-TestConfiguration -configTarget "DoesnotExist.value" -withValue "value"
$config = Initialize-TestConfiguration -configTarget "DoesnotExist.value" -withValue "value"

$fileContent = '{
"parameters": {
Expand All @@ -207,15 +207,15 @@ InModuleScope 'ALZ' {
$fileContent
}

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-Scope It `
-Times 0 -Exactly
}

It 'Should replace simple values correctly (Bicep Object)' {
$config = Initialize-TestConfiguration -configTarget "parValue.value" -withValue "value"
$config = Initialize-TestConfiguration -configTarget "parValue.value" -withValue "value"

$fileContent = '{
"parameters": {
Expand All @@ -239,15 +239,15 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It "Should replace 'Parameter' destinations to nested array objects correctly" {
$config = Initialize-TestConfiguration -configTarget "parNested.value.[0].parChildValue.value" -withValue "nested"
$config = Initialize-TestConfiguration -configTarget "parNested.value.[0].parChildValue.value" -withValue "nested"

$fileContent = '{
"parameters": {
Expand Down Expand Up @@ -279,15 +279,15 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Should replace nested values correctly (Plain JSON Object)' {
$config = Initialize-TestConfiguration -configTarget "parNested.value.parChildValue" -withValue "nested"
$config = Initialize-TestConfiguration -configTarget "parNested.value.parChildValue" -withValue "nested"

$fileContent = '{
"parameters": {
Expand Down Expand Up @@ -315,15 +315,15 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Should replace nested values correctly (Bicep Object)' {
$config = Initialize-TestConfiguration -configTarget "parNested.value.parChildValue.value" -withValue "nested"
$config = Initialize-TestConfiguration -configTarget "parNested.value.parChildValue.value" -withValue "nested"

$fileContent = '{
"parameters": {
Expand Down Expand Up @@ -355,7 +355,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -378,16 +378,6 @@ InModuleScope 'ALZ' {
Value = "test"
DefaultValue = "alz"
}
Suffix = [pscustomobject]@{
Description = "The suffix that will be added to all resources created by this deployment."
Targets = @(
[pscustomobject]@{
Name = "parTopLevelManagementGroupSuffix.value"
Destination = "Parameters"
})
Value = "bla"
DefaultValue = ""
}
Location = [pscustomobject]@{
Description = "Deployment location."
Targets = @(
Expand Down Expand Up @@ -434,9 +424,6 @@ InModuleScope 'ALZ' {
}'
$secondFileContent = '{
"parameters": {
"parTopLevelManagementGroupSuffix": {
"value": ""
},
"parLocation": {
"value": ""
}
Expand All @@ -460,7 +447,7 @@ InModuleScope 'ALZ' {
$secondFileContent
}

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $defaultConfig
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $defaultConfig

Should -Invoke -CommandName Out-File -Scope It -Times 2

Expand All @@ -475,7 +462,6 @@ InModuleScope 'ALZ' {
Should -Invoke -CommandName Out-File -ParameterFilter { $FilePath -eq "test1.parameters.json" -and $InputObject -eq $contentStringAfterParsing } -Scope It

$contentAfterParsing = ConvertFrom-Json -InputObject $secondFileContent -AsHashtable
$contentAfterParsing.parameters.parTopLevelManagementGroupSuffix.value = 'bla'
$contentAfterParsing.parameters.parLocation.value = 'eastus'

$contentStringAfterParsing = ConvertTo-Json -InputObject $contentAfterParsing
Expand All @@ -485,11 +471,11 @@ InModuleScope 'ALZ' {

It 'Computed, Processed array values replace values correctly' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '@($args | Select-Object -Unique)'
Value = @(
Process = '@($args | Select-Object -Unique)'
Value = @(
"1",
"1",
"3"
Expand Down Expand Up @@ -524,7 +510,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -533,11 +519,11 @@ InModuleScope 'ALZ' {

It 'Computed, Processed array values replace values correctly in a case insensitive deduplication.' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '@($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)'
Value = @(
Process = '@($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)'
Value = @(
"A",
"a",
"A",
Expand Down Expand Up @@ -573,7 +559,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -582,11 +568,11 @@ InModuleScope 'ALZ' {

It 'Computed, Processed array values replace values correctly and keep array type when only one item remains.' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '@($args | Select-Object -Unique)'
Value = @(
Process = '@($args | Select-Object -Unique)'
Value = @(
"1",
"1",
"1"
Expand Down Expand Up @@ -621,7 +607,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -630,10 +616,10 @@ InModuleScope 'ALZ' {

It 'Computed, Processed values replace values correctly' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '($args[0] -eq "eastus") ? "eastus2" : ($args[0] -eq "eastus2") ? "eastus" : $args[0]'
Process = '($args[0] -eq "eastus") ? "eastus2" : ($args[0] -eq "eastus2") ? "eastus" : $args[0]'
Value = "eastus"
Targets = @(
[pscustomobject]@{
Expand Down Expand Up @@ -665,7 +651,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -674,10 +660,10 @@ InModuleScope 'ALZ' {

It 'Computed, Processed values replace values correctly' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '($args[0] -eq "goodbye") ? "Hello" : "Goodbye"'
Process = '($args[0] -eq "goodbye") ? "Hello" : "Goodbye"'
Value = "goodbye"
Targets = @(
[pscustomobject]@{
Expand Down Expand Up @@ -709,7 +695,7 @@ InModuleScope 'ALZ' {

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
Expand All @@ -718,7 +704,7 @@ InModuleScope 'ALZ' {

It 'Multiple files with file specific configuration should be changed correctly' {
$defaultConfig = [pscustomobject]@{
Value1 = [pscustomobject]@{
Value1 = [pscustomobject]@{
Description = "The prefix that will be added to all resources created by this deployment."
Targets = @(
[pscustomobject]@{
Expand All @@ -729,7 +715,7 @@ InModuleScope 'ALZ' {
Value = "value1"
DefaultValue = "alz"
}
Value2 = [pscustomobject]@{
Value2 = [pscustomobject]@{
Description = "The prefix that will be added to all resources created by this deployment."
Targets = @(
[pscustomobject]@{
Expand Down Expand Up @@ -760,11 +746,11 @@ InModuleScope 'ALZ' {
Mock -CommandName Get-ChildItem -ParameterFilter { $Path -match 'config$' } -MockWith {
@(
[PSCustomObject]@{
Name = 'test1.parameters.json'
Name = 'test1.parameters.json'
FullName = 'test1.parameters.json'
},
[PSCustomObject]@{
Name = 'test2.parameters.json'
Name = 'test2.parameters.json'
FullName = 'test2.parameters.json'
}
)
Expand All @@ -777,7 +763,7 @@ InModuleScope 'ALZ' {
$secondFileContent
}

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $defaultConfig
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $defaultConfig

Should -Invoke -CommandName Out-File -Scope It -Times 2

Expand Down
Loading