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:5.7.1, Az.Accounts, Az.Resources
modules-to-cache: InvokeBuild, PSScriptAnalyzer, Pester:6.0.0, Az.Accounts, Az.Resources
shell: pwsh
- uses: actions/checkout@v3
- name: Run Tests
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
Assert-MockCalled -ModuleName FinOpsToolkit -CommandName 'Write-Progress' -Times 4
Should -Invoke -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
Assert-MockCalled -CommandName 'Initialize-FinOpsHubDeployment' -Times 1 -ParameterFilter { $WhatIf -eq $true }
Should -Invoke -CommandName 'Initialize-FinOpsHubDeployment' -Times 1 -ParameterFilter { $WhatIf -eq $true }
@('CreateResourceGroup', 'CreateTempDirectory', 'DownloadTemplate', 'DeployFinOpsHub') | ForEach-Object {
Assert-MockCalled -CommandName 'Test-ShouldProcess' -Times 1 -ParameterFilter { $Action -eq $_ }
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-AzResourceGroup' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroup' -Times 1
Should -Invoke -CommandName 'Get-AzResourceGroup' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-AzResourceGroup' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroup' -Times 0
Should -Invoke -CommandName 'Get-AzResourceGroup' -Times 1
Should -Invoke -CommandName 'New-AzResourceGroup' -Times 0
}
}

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

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

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

# Assert
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter { @{ TemplateFile = $templateFile } } -Times 1
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'Get-ChildItem' -Times 1
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'Get-ChildItem' -Times 1
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -Times 0
Should -Invoke -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
Assert-MockCalled -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
Should -Invoke -CommandName 'New-AzResourceGroupDeployment' -ParameterFilter {
$TemplateParameterObject.enableNatGateway -eq $true
} -Times 1
}
Expand Down
Loading
Loading