forked from psget/psget
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGetPsGet.tests.ps1
107 lines (90 loc) · 4.41 KB
/
GetPsGet.tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
$PSScriptRoot = $MyInvocation.MyCommand.Path | Split-Path
if(-not $pester) {
Write-Warning "The tests for GetPsGet should be executed using the Run-Tests.ps1 script or Invoke-AllTests.cmd batch script"
exit -1;
}
function Remove-PsGetModule {
Get-Module -Name PsGet | Remove-Module -ErrorAction Stop
Get-Module -Name PsGet -ListAvailable | Select-Object -ExpandProperty ModuleBase | Remove-Item -Recurse
}
function SimulateBootstrapDownload {
Get-Content -Path $PSScriptRoot\GetPsGet.ps1 | Out-String
}
Remove-Variable -Name PsGetDestinationModulePath -ErrorAction SilentlyContinue
# backup current PSModulePath before testing
$OriginalPSModulePath = $Env:PSModulePath
# default PSModulePath is '{userpath};{systempath}'
$DefaultUserPSModulePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules
$DefaultGlobalPSModulePath = Join-Path -Path $env:CommonProgramFiles -ChildPath "Modules"
$DefaultPSModulePath = $DefaultUserPSModulePath,$DefaultGlobalPSModulePath -join ';'
Describe "GetPsGet.ps1" {
try {
It "Should support the default PSModulePath" {
$Env:PSModulePath = $DefaultPSModulePath
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $DefaultUserPSModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
}
It "Should support the default PSModulePath with a prepended Program Files-relative module path" {
$Env:PSModulePath = "$Env:ProgramFiles\TestPSModulePath;$DefaultPSModulePath"
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $DefaultUserPSModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
}
It "Should support the default PSModulePath with a prepended user profile-relative module path" {
$Env:PSModulePath = "$HOME\TestPSModulePath;$DefaultPSModulePath"
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $DefaultUserPSModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
}
It "Should support a PSModulePath missing the default user profile-relative module path" {
$FirstModulePath = "$Env:TEMP\TestPSModulePath"
$Env:PSModulePath = "$FirstModulePath;$DefaultGlobalPSModulePath"
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $FirstModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
}
It "Should support specifying the module install destination" {
$PsGetDestinationModulePath = "$Env:TEMP\TestPSModulePath"
$Env:PSModulePath = "$DefaultPSModulePath;$PsGetDestinationModulePath"
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $PsGetDestinationModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
Remove-Variable -Name PsGetDestinationModulePath
}
It "Should support specifying a module install destination not in the PSModulePath" {
$PsGetDestinationModulePath = "$Env:TEMP\TestPSModulePath"
$Env:PSModulePath = $DefaultPSModulePath
Remove-PsGetModule
SimulateBootstrapDownload | iex
if (-not (Test-Path -Path $PsGetDestinationModulePath\PsGet\PsGet.psm1)) {
throw 'PsGet module was not installed to expected location'
}
Remove-Variable -Name PsGetDestinationModulePath
}
It "Should support ErrorActionPreference = 'Stop' and Set-StrictMode Latest" {
powershell -noprofile -command {
param ($DownloadedScript)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$DownloadedScript | iex
} -args (SimulateBootstrapDownload)
if (-not $?) {
throw "Test failed"
}
}
} finally {
# restore PSModulePath
$Env:PSModulePath = $OriginalPSModulePath
}
}