Skip to content

Commit

Permalink
(temp) fix whatif tests (partial)
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 committed Nov 7, 2024
1 parent 231b5f5 commit 4156951
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

$testLocation = Get-ChocolateyTestLocation
Import-Module "$testLocation\helpers\chocolateyInstaller.psm1"

$Preamble = [scriptblock]::Create("Import-Module '$testLocation\helpers\chocolateyInstaller.psm1'")
}

AfterAll {
Expand All @@ -15,28 +17,22 @@
@{ Scope = 'User' }
@{ Scope = 'Machine' }
) {
Context 'Path "<_>"' -ForEach @("C:\test", "C:\tools") {
BeforeAll {
$Preamble = [scriptblock]::Create("Import-Module '$testLocation\helpers\chocolateyInstaller.psm1'")
}

It 'stores the value in the desired PATH scope' {
$Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$_' -Scope $Scope -WhatIf")

$results = @( Get-WhatIfResult -Preamble $Preamble -Command $Command )
$results[0] | Should -BeExactly "What if: Performing the operation ""Set $Scope environment variable"" on target ""PATH""."

if ($Scope -ne 'Process') {
$results[1] | Should -BeExactly 'What if: Performing the operation "Notify system of changes" on target "Environment variables".'
$results[2] | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".'
}
It 'stores the value <_> in the desired PATH scope' -TestCases @("C:\test", "C:\tools") {
$Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$_' -Scope $Scope -WhatIf")

$results = @( Get-WhatIfResult -Preamble $Preamble -Command $Command )
$results[0] | Should -BeExactly "What if: Performing the operation ""Set $Scope environment variable"" on target ""PATH""."

if ($Scope -ne 'Process') {
$results[1] | Should -BeExactly 'What if: Performing the operation "Notify system of changes" on target "Environment variables".'
$results[2] | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".'
}
}

It 'skips adding the value if it is already present' {
$targetPathEntry = [Environment]::GetEnvironmentVariable('PATH', $Scope) -split ';' | Select-Object -First 1
$Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$targetPathEntry' -Scope $Scope -WhatIf")
Get-WhatIfResult -Preamble $Preamble -Command $Command | Should -BeNullOrEmpty -Because 'we should skip adding values that already exist'
}
It 'skips adding the value if it is already present' {
$targetPathEntry = [Environment]::GetEnvironmentVariable('PATH', $Scope) -split ';' | Select-Object -First 1
$Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$targetPathEntry' -Scope $Scope -WhatIf")
Get-WhatIfResult -Preamble $Preamble -Command $Command | Should -BeNullOrEmpty -Because 'we should skip adding values that already exist'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$Command = [scriptblock]::Create("Update-SessionEnvironment -WhatIf")

$results = Get-WhatIfResult -Preamble $Preamble -Command $Command
$results | Should -BeExactly 'What if: Performing the operation "refresh all environment variables" on target "current process".'
$results | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".'
}
}

Expand Down

0 comments on commit 4156951

Please sign in to comment.