diff --git a/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 b/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 index f145b26261..0e6c58f98f 100644 --- a/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 @@ -22,10 +22,18 @@ Describe 'Get-EnvironmentVariable helper function tests' -Tags Cmdlets { } Context 'Can retrieve the PATH variable without expanding environment names for the Machine scope' { + BeforeAll { + Install-ChocolateyPath -Path "%systemroot%\test" -PathType Machine + } + + AfterAll { + Uninstall-ChocolateyPath -Path "%systemroot%\test" -PathType Machine + } + It 'Retrieves the Machine PATH value with un-expanded environment names' { # We expect there to be an entry similar to the following: "%SystemRoot%\system32", since this # is there by default in a Windows install - Get-EnvironmentVariable -Name 'PATH' -Scope 'Machine' | Should -Match '%[^%;\\]+%' + Get-EnvironmentVariable -Name 'PATH' -Scope 'Machine' -PreserveVariables | Should -Match '%systemroot%\\test' } } } \ No newline at end of file diff --git a/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 b/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 index 5b1a9bc840..7e67ca9e2a 100644 --- a/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 @@ -20,17 +20,21 @@ Describe 'Set-EnvironmentVariable helper function tests' -Tags Cmdlets { } Describe 'Setting environment variable ' -ForEach $variables { - It 'Sets the target environment variable in the proper scope, as well as current process scope' { + BeforeAll { Set-EnvironmentVariable -Name $Name -Value $Value -Scope $Scope - [Environment]::GetEnvironmentVariable($Name, $Scope) | Should -BeExactly $Value - - # We are explicitly checking the Process variable here. - [Environment]::GetEnvironmentVariable($Name, 'Process') | Should -BeExactly $Value } AfterAll { Set-EnvironmentVariable -Name $Name -Value "" -Scope $Scope } + + It 'sets the target environment variable in the proper scope' { + [Environment]::GetEnvironmentVariable($Name, $Scope) | Should -BeExactly $Value + } + + It 'propagates the change to the current process' { + Get-Content "Env:\$Name" | Should -BeExactly $Value + } } } } \ No newline at end of file diff --git a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 index 742bc3da5f..9f8bcccbc6 100644 --- a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 @@ -17,12 +17,13 @@ Update-SessionEnvironment $env:Test | Should -BeExactly 'user-value' $env:Test2 | Should -BeExactly 'machine-value' - $env:Test3 | Should -BeNullOrEmpty -Because 'Process-only values should not be preserved' + $env:Test3 | Should -BeExactly 'process-value' } AfterAll { [Environment]::SetEnvironmentVariable("Test", [string]::Empty, "User") [Environment]::SetEnvironmentVariable("Test2", [string]::Empty, "Machine") + $env:Test3 = '' } } } \ No newline at end of file