Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install and cache PowerShell modules
uses: potatoqualitee/psmodulecache@v6.2.1
with:
modules-to-cache: InvokeBuild, PSScriptAnalyzer, Pester, Az.Accounts, Az.Resources
modules-to-cache: InvokeBuild, PSScriptAnalyzer, Pester:5.7.1, Az.Accounts, Az.Resources
shell: pwsh
- uses: actions/checkout@v3
- name: Run Tests
Expand Down
1 change: 0 additions & 1 deletion src/powershell/Tests/Initialize-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

Remove-Module FinOpsToolkit -ErrorAction SilentlyContinue
Import-Module -FullyQualifiedName "$PSScriptRoot/../FinOpsToolkit.psm1"
Import-Module Pester -Global -ErrorAction Stop

BeforeAll {
# Bring the Monitor functions in to simplify debugging
Expand Down
2 changes: 1 addition & 1 deletion src/powershell/Tests/Integration/CostExports.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Describe 'CostExports' {
-Backfill 12

# Assert
Should -Invoke -ModuleName FinOpsToolkit -CommandName 'Write-Progress' -Times 4
Assert-MockCalled -ModuleName FinOpsToolkit -CommandName 'Write-Progress' -Times 4
$success | Should -Be $true
((Get-Date) - $testStartTime).TotalSeconds | Should -BeGreaterThan 60
}
Expand Down
58 changes: 29 additions & 29 deletions src/powershell/Tests/Unit/Deploy-FinOpsHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ InModuleScope 'FinOpsToolkit' {
Deploy-FinOpsHub -WhatIf -Name $hubName -ResourceGroupName $rgName -Location $location

# Assert
Should -Invoke -CommandName 'Initialize-FinOpsHubDeployment' -Times 1 -ParameterFilter { $WhatIf -eq $true }
Assert-MockCalled -CommandName 'Initialize-FinOpsHubDeployment' -Times 1 -ParameterFilter { $WhatIf -eq $true }
@('CreateResourceGroup', 'CreateTempDirectory', 'DownloadTemplate', 'DeployFinOpsHub') | ForEach-Object {
Should -Invoke -CommandName 'Test-ShouldProcess' -Times 1 -ParameterFilter { $Action -eq $_ }
Assert-MockCalled -CommandName 'Test-ShouldProcess' -Times 1 -ParameterFilter { $Action -eq $_ }
}
}
}
Expand All @@ -55,8 +55,8 @@ InModuleScope 'FinOpsToolkit' {
Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location

# Assert
Should -Invoke -CommandName 'Get-AzResourceGroup' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroup' -Times 1
Assert-MockCalled -CommandName 'Get-AzResourceGroup' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroup' -Times 1
}

It 'Should use RG if it exists' {
Expand All @@ -69,8 +69,8 @@ InModuleScope 'FinOpsToolkit' {
Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location

# Assert
Should -Invoke -CommandName 'Get-AzResourceGroup' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroup' -Times 0
Assert-MockCalled -CommandName 'Get-AzResourceGroup' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroup' -Times 0
}
}

Expand All @@ -85,7 +85,7 @@ InModuleScope 'FinOpsToolkit' {
Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location

# Assert
Should -Invoke -CommandName 'Initialize-FinOpsHubDeployment' -Times 1
Assert-MockCalled -CommandName 'Initialize-FinOpsHubDeployment' -Times 1
}
}

Expand All @@ -111,7 +111,7 @@ InModuleScope 'FinOpsToolkit' {
Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location

# Assert
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -Times 1
}
It 'Should add tags to the deployment' -Skip {
}
Expand All @@ -130,7 +130,7 @@ InModuleScope 'FinOpsToolkit' {
It 'Should throw if template file is not found' {
Mock -CommandName 'Get-ChildItem'
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -Version 'latest' } | Should -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
}

Context 'More' {
Expand All @@ -142,14 +142,14 @@ InModuleScope 'FinOpsToolkit' {

It 'Should deploy the template without throwing' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter { @{ TemplateFile = $templateFile } } -Times 1
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter { @{ TemplateFile = $templateFile } } -Times 1
}

It 'Should deploy the template with tags' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -Tags @{ Test = 'Tag' } -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
@{
TemplateParameterObject = @{
tags = @{
Expand All @@ -163,8 +163,8 @@ InModuleScope 'FinOpsToolkit' {
It 'Should deploy the template with StorageSku' {
$storageSku = 'Premium_ZRS'
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -StorageSku $storageSku -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
@{
TemplateParameterObject = @{
storageSku = $storageSku
Expand All @@ -176,17 +176,17 @@ InModuleScope 'FinOpsToolkit' {
It 'Should deploy the template with RemoteHubStorageUri' {
$remoteHubStorageUri = 'https://primaryhub.dfs.core.windows.net/'
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -RemoteHubStorageUri $remoteHubStorageUri -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.remoteHubStorageUri -eq $remoteHubStorageUri
} -Times 1
}

It 'Should deploy the template with RemoteHubStorageKey' {
$remoteHubStorageKey = 'abc123...xyz789=='
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -RemoteHubStorageKey $remoteHubStorageKey -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.remoteHubStorageKey -eq $remoteHubStorageKey
} -Times 1
}
Expand All @@ -195,8 +195,8 @@ InModuleScope 'FinOpsToolkit' {
$remoteHubStorageUri = 'https://primaryhub.dfs.core.windows.net/'
$remoteHubStorageKey = 'abc123...xyz789=='
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -RemoteHubStorageUri $remoteHubStorageUri -RemoteHubStorageKey $remoteHubStorageKey -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.remoteHubStorageUri -eq $remoteHubStorageUri -and $TemplateParameterObject.remoteHubStorageKey -eq $remoteHubStorageKey
} -Times 1
}
Expand All @@ -216,54 +216,54 @@ InModuleScope 'FinOpsToolkit' {

It 'Should default to public access without a NAT Gateway' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $true -and -not $TemplateParameterObject.ContainsKey('enableNatGateway')
} -Times 1
}

It "Should map -NetworkMode 'public' to enablePublicAccess and no NAT Gateway" {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'public' -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $true -and -not $TemplateParameterObject.ContainsKey('enableNatGateway')
} -Times 1
}

It "Should map -NetworkMode 'vnet' to private access without a NAT Gateway" {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'vnet' -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $false -and -not $TemplateParameterObject.ContainsKey('enableNatGateway')
} -Times 1
}

It "Should map -NetworkMode 'private' to private access with a NAT Gateway" {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'private' -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $false -and $TemplateParameterObject.enableNatGateway -eq $true
} -Times 1
}

It 'Should map deprecated -DisablePublicAccess to vnet (no NAT Gateway)' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -DisablePublicAccess -Version 'latest' -WarningAction 'SilentlyContinue' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $false -and -not $TemplateParameterObject.ContainsKey('enableNatGateway')
} -Times 1
}

It 'Should let -NetworkMode win over deprecated -DisablePublicAccess' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'private' -DisablePublicAccess -Version 'latest' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enablePublicAccess -eq $false -and $TemplateParameterObject.enableNatGateway -eq $true
} -Times 1
}

It 'Should throw when private mode targets a version older than 15.0' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'private' -Version '14.0' } | Should -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -Times 0
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -Times 0
}

It 'Should pass enableNatGateway when private mode targets version 15.0 or later' {
{ Deploy-FinOpsHub -Name $hubName -ResourceGroup $rgName -Location $location -NetworkMode 'private' -Version '15.0' } | Should -Not -Throw
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enableNatGateway -eq $true
} -Times 1
}
Expand Down
50 changes: 12 additions & 38 deletions src/powershell/Tests/Unit/DocsLinks.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -286,56 +286,30 @@ Describe 'Documentation links' {
}

Context 'docs-mslearn: No learn.microsoft.com URLs' {
$learnMicrosoftLinks = @($mslearnUrls | Where-Object { $_.Url -match 'learn\.microsoft\.com' })
if ($learnMicrosoftLinks.Count -gt 0) {
It 'Should not contain https://learn.microsoft.com links: <SourceRel>:<LineNumber>' -ForEach $learnMicrosoftLinks {
$Url | Should -Not -Match 'learn\.microsoft\.com' -Because "links in docs-mslearn should use root-relative paths (e.g., /azure/...) instead of full URLs since docs are deployed to learn.microsoft.com (${SourceRel}:${LineNumber})"
}
}
else {
It 'Should not contain https://learn.microsoft.com links' {
$learnMicrosoftLinks | Should -BeNullOrEmpty -Because 'docs-mslearn should not contain fully qualified learn.microsoft.com URLs'
}

It 'Should not contain https://learn.microsoft.com links: <SourceRel>:<LineNumber>' -ForEach ($mslearnUrls | Where-Object { $_.Url -match 'learn\.microsoft\.com' }) {
$Url | Should -Not -Match 'learn\.microsoft\.com' -Because "links in docs-mslearn should use root-relative paths (e.g., /azure/...) instead of full URLs since docs are deployed to learn.microsoft.com (${SourceRel}:${LineNumber})"
}
}

Context 'docs-mslearn: No language locale in MS Learn links' {
$localizedMsLearnLinks = @($mslearnUrls | Where-Object { $_.Url -match 'learn\.microsoft\.com/[a-z]{2}-[a-z]{2}/' })
if ($localizedMsLearnLinks.Count -gt 0) {
It 'Should not contain language locale in URL: <SourceRel>:<LineNumber> <Url>' -ForEach $localizedMsLearnLinks {
$Url | Should -Not -Match 'learn\.microsoft\.com/[a-z]{2}-[a-z]{2}/' -Because "MS Learn links should not include language locale segments like /en-us/ (${SourceRel}:${LineNumber})"
}
}
else {
It 'Should not contain language locale in MS Learn links' {
$localizedMsLearnLinks | Should -BeNullOrEmpty -Because 'MS Learn links should not include language locale segments like /en-us/'
}

It 'Should not contain language locale in URL: <SourceRel>:<LineNumber> <Url>' -ForEach ($mslearnUrls | Where-Object { $_.Url -match 'learn\.microsoft\.com/[a-z]{2}-[a-z]{2}/' }) {
$Url | Should -Not -Match 'learn\.microsoft\.com/[a-z]{2}-[a-z]{2}/' -Because "MS Learn links should not include language locale segments like /en-us/ (${SourceRel}:${LineNumber})"
}
}

Context 'docs-mslearn: No known broken external URLs' {
if ($knownBrokenExternalUrlMatches.Count -gt 0) {
It 'Should not contain known broken external URL: <SourceRel>:<LineNumber> <Url>' -ForEach $knownBrokenExternalUrlMatches {
$Url | Should -Not -Match $Pattern -Because "known broken external URLs should not appear in docs-mslearn content (${SourceRel}:${LineNumber})"
}
}
else {
It 'Should not contain known broken external URLs' {
$knownBrokenExternalUrlMatches | Should -BeNullOrEmpty -Because 'docs-mslearn should not contain any known broken external URLs'
}

It 'Should not contain known broken external URL: <SourceRel>:<LineNumber> <Url>' -ForEach $knownBrokenExternalUrlMatches {
$Url | Should -Not -Match $Pattern -Because "known broken external URLs should not appear in docs-mslearn content (${SourceRel}:${LineNumber})"
}
}

Context 'docs-mslearn: No incomplete placeholder external URLs' {
if ($incompleteExternalUrlMatches.Count -gt 0) {
It 'Should not contain incomplete placeholder URL: <SourceRel>:<LineNumber> <Url>' -ForEach $incompleteExternalUrlMatches {
$Url | Should -Not -Match $Pattern -Because "incomplete placeholder URLs should not appear in docs-mslearn content (${SourceRel}:${LineNumber})"
}
}
else {
It 'Should not contain incomplete placeholder external URLs' {
$incompleteExternalUrlMatches | Should -BeNullOrEmpty -Because 'docs-mslearn should not contain placeholder external URLs'
}

It 'Should not contain incomplete placeholder URL: <SourceRel>:<LineNumber> <Url>' -ForEach $incompleteExternalUrlMatches {
$Url | Should -Not -Match $Pattern -Because "incomplete placeholder URLs should not appear in docs-mslearn content (${SourceRel}:${LineNumber})"
}
}

Expand Down
Loading
Loading