Skip to content

Commit

Permalink
(chocolatey#3225) Add Pester Tests to ensure environment
Browse files Browse the repository at this point in the history
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
corbob committed Jun 25, 2023
1 parent 7e89da5 commit 3dc4416
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/chocolatey-tests/features/EnvironmentVariables.Tests.ps1
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
}
}

0 comments on commit 3dc4416

Please sign in to comment.