Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
setup tests: conditionally test default installation
Browse files Browse the repository at this point in the history
Default installation (no arguments or preexisting environment variables)
can be tested only when the test machine does not already have Chocolatey
installed in the default location (otherwise it would get overwritten).

To enable these tests, make sure your Chocolatey is installed in a custom
location.
  • Loading branch information
jberezanski committed Jun 13, 2014
1 parent fa4f28a commit a00ec70
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/unit/Initialize-Chocolatey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,62 @@ function Setup-ChocolateyInstallationPackage
Import-Module "$tmpDir\chocolateysetup.psm1"
}

function Get-DefaultChocolateyInstallDir
{
$programData = [Environment]::GetFolderPath([Environment+SpecialFolder]::CommonApplicationData)
$chocolateyPath = Join-Path $programData chocolatey
return $chocolateyPath
}

function Execute-ChocolateyInstallationInDefaultDir($scriptBlock)
{
$defaultDir = Get-DefaultChocolateyInstallDir
if (Test-Path $defaultDir) {
Write-Warning "Skipping default installation test because the default installation directory already exists ($defaultDir)"
return
}
$script:installDir = $defaultDir
try
{
& $scriptBlock
}
finally
{
Write-Debug "Removing default installation directory if exists ($defaultDir)"
Get-Item $defaultDir | Remove-Item -Recurse -Force
}
}

Describe "Initialize-Chocolatey" {
# note: the specs below are correct when installing with administrative permissions with UAC enabled
# the test suite is always run elevated, so no easy way to test limited user install for now

Context "When installing with `$Env:ChocolateyInstall not set and no arguments" {
Setup-ChocolateyInstallationPackage

Execute-WithEnvironmentBackup {
Setup-ChocolateyInstall $null

Execute-ChocolateyInstallationInDefaultDir {
Initialize-Chocolatey

Verify-ExpectedContentInstalled $installDir

It "should create ChocolateyInstall at Process scope" {
Assert-ChocolateyInstallIs $installDir 'Process'
}

It "should create ChocolateyInstall at User scope" {
Assert-ChocolateyInstallIs $installDir 'User'
}

It "should not create ChocolateyInstall at Machine scope" {
Assert-ChocolateyInstallIsNull 'Machine'
}
}
}
}

Context "When installing with `$Env:ChocolateyInstall not set, with explicit chocolateyPath" {
Setup-ChocolateyInstallationPackage

Expand Down

0 comments on commit a00ec70

Please sign in to comment.