Skip to content

Instantly share code, notes, and snippets.

@aw230012
Created January 3, 2018 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aw230012/133ce7c46f71630c9795c1ca94d14cf0 to your computer and use it in GitHub Desktop.
Save aw230012/133ce7c46f71630c9795c1ca94d14cf0 to your computer and use it in GitHub Desktop.
New Recovery Vault Pester Tests
Describe 'New-RecoveryVault Tests' {
$configurationFile = "$PSScriptRoot\\..\\Data\\RecoveryVaultConfiguration.json"
$configurationData = (Get-Content $configurationFile -Raw | ConvertFrom-Json).ConfigurationItems
Context 'Resource Group Tests' {
$rg = Get-AzureRmResourceGroup -Name $configurationData.ResourceGroup.Name
It 'Resource Group Exists' {
$rg | Select-Object -ExpandProperty ResourceGroupName | Should Be $configurationData.ResourceGroup.Name
}
It 'Is Correct Location' {
$expectedValue = $configurationData.Location.Name -replace ' ', ''
$rg.Location | Should Be $expectedValue
}
}
Context 'Recovery Vault Tests' {
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $configurationData.ResourceGroup.Name -Name $configurationData.RecoveryVault.Name
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
$policy = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $configurationData.RecoveryVault.Policy.Name
It 'Recovery Vault Exists' {
$vault | Select-Object -ExpandProperty Name | Should Be $configurationData.RecoveryVault.Name
}
It 'Backup Policy Exists' {
$policy | Select-Object -ExpandProperty Name | Should Be $configurationData.RecoveryVault.Policy.Name
}
}
}
@badalk
Copy link

badalk commented Aug 19, 2018

you have only 1 parameters file but typically you may want to test your deployment with multiple parameter files, each having a particular combination of values. How do you achieve that? I tried using -Testcases in It block but I am facing some issues

Regards
Badal

@MarkWarneke
Copy link

@badlak

you have only 1 parameters file but typically you may want to test your deployment with multiple parameter files, each having a particular combination of values. How do you achieve that? I tried using -Testcases in It block but I am facing some issues

Regards
Badal

you could use a param() block in the beginning to pass in a different configurations file. That way you could reuse the tests for different configurations.

param(
  [string] $ConfigurationFile = "$PSScriptRoot\\..\\Data\\RecoveryVaultConfiguration.json"
)

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment