Variables.Tests.ps1
#################################################################################################### # Declarations #################################################################################################### # Set InformationPreference $InformationPreference = "Continue" #################################################################################################### # Functions #################################################################################################### # Add modules folder to path if not already added if (!$env:PSModulePath.EndsWith(";$(Get-Location)\Modules")) { $env:PSModulePath += ";$(Get-Location)\Modules" } # Import functions from BitTitan.Runbooks.Modules Import-Module BitTitan.Runbooks.Common -Force #################################################################################################### # The tests #################################################################################################### describe "Modules/BitTitan.Runbooks.Common/Variables/Set-DefaultValue" -Tags "module", "common", "unit" { context "when given a variable containing null" { it "sets the variable to the default value" { $Global:variable = $null $variable | Set-DefaultValue 42 $variable | Should Be 42 $Global:variable = $null $variable | Set-DefaultValue "string" $variable | Should Be "string" $Global:variable = $null $variable | Set-DefaultValue $true $variable | Should Be $true $Global:variable = $null $variable | Set-DefaultValue @(1, 2, 3) $variable | Should Be @(1, 2, 3) } } context "when given a variable already containing a value" { it "does not change the value of the variable" { $Global:variable = 5 $variable | Set-DefaultValue 42 $variable | Should Be 5 $Global:variable = "foo" $variable | Set-DefaultValue "bar" $variable | Should Be "foo" $Global:variable = $false $variable | Set-DefaultValue $true $variable | Should Be $false $Global:variable = @(1, 2) $variable | Set-DefaultValue @(1, 2, 3) $variable | Should Be @(1, 2) } } } |