diff --git a/tests/pester-tests/commands/choco-install.Tests.ps1 b/tests/pester-tests/commands/choco-install.Tests.ps1 index aa58a25e61..67b40473f2 100644 --- a/tests/pester-tests/commands/choco-install.Tests.ps1 +++ b/tests/pester-tests/commands/choco-install.Tests.ps1 @@ -83,7 +83,79 @@ $PackageUnderTest = "installpackage" - $Output = Invoke-Choco install $PackageUnderTest --confirm + $Output = Invoke-Choco install $PackageUnderTest --debug --confirm + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Installed a package to the lib directory" { + "$env:ChocolateyInstall\lib\$PackageUnderTest" | Should -Exist + } + + # We are skipping this for now, until we have stabilized the directory + # path reporting functionality. There are times that this test will + # fail due to Chocolatey not reporting the path. + # This failure seems to happen randomly, and is therefore not a + # reliable test we can make. + It "Outputs the installation directory (which should exist)" -Skip { + $directoryPath = "$env:ChocolateyInstall\lib\$PackageUnderTest" + $lineRegex = [regex]::Escape($directoryPath) + + $foundPath = $Output.Lines -match $lineRegex + $foundPath | Should -Not -BeNullOrEmpty + $foundPath | Should -Exist + } + + It "Installs the expected version of the package" { + "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" | Should -Exist + [xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" + $XML.package.metadata.version | Should -Be "1.0.0" + } + + It "Creates a Console Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\console.exe" | Should -Exist + } + + It "Creates a Graphical Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\graphical.exe" | Should -Exist + } + + It "Does not create a Shim for Ignored Executable in the Bin Directory" { + "$env:ChocolateyInstall\bin\not.installed.exe" | Should -Not -Exist + } + + It "Does not create a Shim for Ignored Executable (with mismatched case) in the Bin Directory" { + "$env:ChocolateyInstall\bin\casemismatch.exe" | Should -Not -Exist + } + + It "Does not create an extensions folder for the package" { + "$env:ChocolateyInstall\extensions\$PackageUnderTest" | Should -Not -Exist + } + + It "Contains the output of the ChocolateyInstall.ps1 script" { + $Output.Lines | Should -Contain "Ya!" + } + + It "Outputs a message showing that installation was successful" { + $Output.String | Should -Match "Chocolatey installed 1/1 packages\." + } + + It "Should mention that package hash verification has been skipped" { + $Output.Lines | Should -Contain "Skipping package hash validation as feature 'usePackageHashValidation' is not enabled." -Because $Output.String + } + } + + Context "Installing a Package (Happy Path) with hash validation enabled" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $null = Enable-ChocolateyFeature -Name "usePackageHashValidation" + + $PackageUnderTest = "installpackage" + + $Output = Invoke-Choco install $PackageUnderTest --debug --confirm } It "Exits with Success (0)" { @@ -141,6 +213,14 @@ It "Outputs a message showing that installation was successful" { $Output.String | Should -Match "Chocolatey installed 1/1 packages\." } + + It "Should mention that package hash verification was skipped since local folder source is being used" { + if ((Test-HasNuGetV3Source) -or (-not $env:TEST_KITCHEN)) { + $Output.Lines | Should -Contain "Source does not provide a package hash, skipping package hash validation." -Because $Output.String + } else { + $Output.Lines | Should -Contain "Package hash matches expected hash." -Because $Output.String + } + } } Context "Installing a Package (Happy Path) including configured sources" {