forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#3225) Add Pester Tests to ensure environment
Make use of the test-environment package that already exists to get the environment variables set by Chocolatey and ensure that key variables are set as they should be.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
tests/chocolatey-tests/features/EnvironmentVariables.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Describe "Ensuring Chocolatey Environment variables are correct (<_>)" -ForEach @( | ||
"config" | ||
"cli" | ||
) -Tag EnvironmentVariables, Chocolatey { | ||
BeforeDiscovery { | ||
$TestedVariables = @( | ||
@{ Name = 'TEMP' ; Value = "C:\Temp\$PID" } | ||
@{ Name = 'TMP' ; Value = "C:\Temp\$PID" } | ||
@{ Name = 'ChocolateyPackageFolder' ; Value = '{0}\lib\test-environment' } | ||
@{ Name = 'ChocolateyPackageName' ; Value = 'test-environment' } | ||
@{ Name = 'ChocolateyPackageTitle' ; Value = 'test-environment (Install)' } | ||
@{ Name = 'ChocolateyPackageVersion' ; Value = '1.0.0' } | ||
) | ||
} | ||
|
||
BeforeAll { | ||
Initialize-ChocolateyTestInstall | ||
New-ChocolateyInstallSnapshot | ||
$cacheDir = "C:\Temp\$PID" | ||
switch ($_) { | ||
'config' { | ||
Invoke-Choco config set --name=cachelocation --value $cacheDir | ||
} | ||
'cli' { | ||
$cacheArg = "--cache-location='$cacheDir'" | ||
} | ||
} | ||
$Output = Invoke-Choco install test-environment --version 1.0.0 $cacheArg | ||
} | ||
|
||
AfterAll { | ||
Remove-ChocolateyTestInstall | ||
} | ||
|
||
It "Should exit with success (0)" { | ||
$Output.ExitCode | Should -Be 0 -Because $Output.String | ||
} | ||
|
||
It 'Should Output the expected value for <Name> environment variable' -ForEach $TestedVariables { | ||
$ExpectedLine = "$Name=$Value" -f $env:ChocolateyInstall | ||
$Output.Lines | Should -Contain $ExpectedLine -Because $Output.String | ||
} | ||
} |