Skip to content

Commit

Permalink
(maint) Fix test executions after internal changes
Browse files Browse the repository at this point in the history
This commit updates the tests we have for open source
Chocolatey CLI after the changes we expect to need to be
made in our internal structure to make sure they still
are able to pass.
  • Loading branch information
AdmiringWorm committed Mar 10, 2023
1 parent b6a7753 commit ca4de8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 12 additions & 4 deletions tests/chocolatey-tests/chocolatey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
# This is skipped when not run in CI because it modifies the local system.
Context 'License warning is worded properly' -Tag FossOnly -Skip:((-not $env:TEST_KITCHEN) -or (-not (Test-ChocolateyVersionEqualOrHigherThan '1.0.0'))) {
BeforeAll {
Restore-ChocolateyInstallSnapshot
$null = Enable-ChocolateySource 'hermes-setup'
$null = Invoke-Choco install chocolatey-license-business -y
$Output = Invoke-Choco list -lo
}
Expand All @@ -210,10 +212,12 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
# This is skipped when not run in CI because it modifies the local system.
Context 'PowerShell Profile comments updated correctly' -Skip:((-not $env:TEST_KITCHEN) -or (-not (Test-ChocolateyVersionEqualOrHigherThan '1.0.0'))) {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Remove-Item $Profile.CurrentUserCurrentHost -ErrorAction Ignore
New-Item $Profile.CurrentUserCurrentHost -Force
$chocolatey = (Invoke-Choco list chocolatey -lo -r --exact).Lines | ConvertFrom-ChocolateyOutput -Command List
Enable-ChocolateySource -Name local
Enable-ChocolateySource -Name hermes-setup
$null = Invoke-Choco install chocolatey -f --version $chocolatey.Version
}

Expand All @@ -237,6 +241,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
# This is skipped when not run in CI because it modifies the local system.
Context 'PowerShell Profile properly updated when Windows thinks a 5 byte file is signed' -Skip:((-not $env:TEST_KITCHEN) -or (-not (Test-ChocolateyVersionEqualOrHigherThan '1.1.0'))) {
BeforeAll {
Restore-ChocolateyInstallSnapshot
New-Item $Profile.CurrentUserCurrentHost -Force
"" | Set-Content -Path $Profile.CurrentUserCurrentHost -Encoding UTF8
$chocolatey = (Invoke-Choco list chocolatey -lo -r --exact).Lines | ConvertFrom-ChocolateyOutput -Command List
Expand Down Expand Up @@ -272,6 +277,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
}
) {
BeforeAll {
Restore-ChocolateyInstallSnapshot
$chocolatey = (Invoke-Choco list chocolatey -lo -r --exact).Lines | ConvertFrom-ChocolateyOutput -Command List

foreach ($shim in $RemovedShims) {
Expand All @@ -286,6 +292,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
}

Enable-ChocolateySource -Name local
Enable-ChocolateySource -Name hermes-setup
$Output = Invoke-Choco install chocolatey -f --version $chocolatey.Version --no-progress
}

Expand All @@ -304,6 +311,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat

Context 'Ensure a corrupted config file does not cause errors' -Tag ConfigFile -Skip:(-not (Test-ChocolateyVersionEqualOrHigherThan '1.1.0')) {
BeforeAll {
Restore-ChocolateyInstallSnapshot
$ChocolateyConfigLocation = "$env:ChocolateyInstall/config/chocolatey.config"
$BadContent = "<chocolatey></chocolatey>BadFile"
# Make sure we have a chocolatey config file
Expand All @@ -327,9 +335,9 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
'powershell'
) -Skip:((-not $env:TEST_KITCHEN) -or (-not (Test-ChocolateyVersionEqualOrHigherThan '1.1.0'))) {
BeforeAll {
New-ChocolateyInstallSnapshot
# TODO: Internalize pwsh and powershell packages...
$pwshInstall = Invoke-Choco install $_ -y -s https://community.chocolatey.org/api/v2/
Restore-ChocolateyInstallSnapshot
Enable-ChocolateySource -Name hermes-setup
$pwshInstall = Invoke-Choco install $_ -y
$ChocoUnzipped = "$(Get-TempDirectory)$(New-Guid)"
$modulePath = "$ChocoUnzipped/tools/chocolateySetup.psm1"

Expand Down Expand Up @@ -358,7 +366,7 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat
if (Test-Path $ChocoUnzipped) {
Remove-Item $ChocoUnzipped -Force -Recurse
}
$null = Invoke-Choco uninstall $_ -y -s https://community.chocolatey.org/api/v2/ --force-dependencies
$null = Invoke-Choco uninstall $_ -y --force-dependencies
Remove-ChocolateyInstallSnapshot
}

Expand Down
10 changes: 7 additions & 3 deletions tests/chocolatey-tests/commands/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ To install a local, or remote file, you may use:

Context "Installing commercial package with custom commandlets" -Tag FossOnly {
BeforeAll {
New-ChocolateyInstallSnapshot
Restore-ChocolateyInstallSnapshot

$Output = Invoke-Choco install get-chocolateyunzip-licensed --confirm
}
Expand All @@ -1332,7 +1332,8 @@ To install a local, or remote file, you may use:

Context "Installing license only package on open source" -Tag FossOnly {
BeforeAll {
New-ChocolateyInstallSnapshot
Restore-ChocolateyInstallSnapshot
Enable-ChocolateySource -Name hermes-setup

$Output = Invoke-Choco install business-only-license --confirm
}
Expand Down Expand Up @@ -1456,7 +1457,6 @@ To install a local, or remote file, you may use:
Context "Installing package that makes use of new Get Chocolatey Path helper" {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Enable-ChocolateySource -Name 'local'

$Output = Invoke-Choco install test-chocolateypath -y
}
Expand Down Expand Up @@ -1723,9 +1723,13 @@ To install a local, or remote file, you may use:
$nuspec | Set-Content -Path $nuspecPath
"readme content" | Set-Content -Path "$tempPath/$packageName/readme.md"

Enable-ChocolateySource -Name hermes-setup

$null = Invoke-Choco install nuget.commandline
$null = & "$env:ChocolateyInstall/bin/nuget.exe" pack $nuspecPath

Disable-ChocolateySource -Name hermes-setup

$Output = Invoke-Choco install $packageName --source .
}

Expand Down

0 comments on commit ca4de8f

Please sign in to comment.