This repository has been archived by the owner on Dec 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathInit.Tests.ps1
120 lines (94 loc) · 4.2 KB
/
Init.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
108
109
110
111
112
113
114
115
116
117
118
119
120
. .\Utils.ps1
. .\Init.ps1
. .\TestUtils.ps1
Describe 'Init-Posh-Gvm' {
Context 'PGVM-Dir with only a grails folder' {
Mock-PGVM-Dir
Mock Check-JAVA-HOME -verifiable
Mock Update-Candidates-Cache -verifiable
Mock Init-Candidate-Cache -verifiable
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'grails' -and $Version -eq 'current' }
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'groovy' -and $Version -eq 'current' }
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'bla' -and $Version -eq 'current' }
$Script:PGVM_CANDIDATES_PATH = "$Global:PGVM_DIR\.meta\candidates.txt"
$Script:GVM_CANDIDATES = 'grails','groovy','bla'
Init-Posh-Gvm
It "creates .meta" {
Test-Path "$Global:PGVM_DIR\.meta" | Should Be $true
}
It "creates grails" {
Test-Path "$Global:PGVM_DIR\grails" | Should Be $true
}
It "creates groovy" {
Test-Path "$Global:PGVM_DIR\groovy" | Should Be $true
}
It "creates bla" {
Test-Path "$Global:PGVM_DIR\bla" | Should Be $true
}
It "calls methods to test JAVA_HOME, API version, loads candidate cache and setup env variables" {
Assert-VerifiableMocks
}
Reset-PGVM-Dir
}
Context 'PGVM-Dir with only a grails folder and a candidates list' {
Mock-PGVM-Dir
Mock Check-JAVA-HOME -verifiable
Mock Update-Candidates-Cache
Mock Init-Candidate-Cache -verifiable
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'grails' -and $Version -eq 'current' }
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'groovy' -and $Version -eq 'current' }
Mock Set-Env-Candidate-Version -verifiable -parameterFilter { $Candidate -eq 'bla' -and $Version -eq 'current' }
$Script:PGVM_CANDIDATES_PATH = "$Global:PGVM_DIR\.meta\candidates.txt"
New-Item -ItemType Directory "$Global:PGVM_DIR\.meta" | Out-Null
New-Item -ItemType File $Script:PGVM_CANDIDATES_PATH | Out-Null
$Script:GVM_CANDIDATES = 'grails','groovy','bla'
Init-Posh-Gvm
It "creates .meta" {
Test-Path "$Global:PGVM_DIR\.meta" | Should Be $true
}
It "creates grails" {
Test-Path "$Global:PGVM_DIR\grails" | Should Be $true
}
It "creates groovy" {
Test-Path "$Global:PGVM_DIR\groovy" | Should Be $true
}
It "creates bla" {
Test-Path "$Global:PGVM_DIR\bla" | Should Be $true
}
It "calls methods to test JAVA_HOME, API version, loads candidate cache and setup env variables" {
Assert-VerifiableMocks
}
It "does not call update-candidates-cache" {
Assert-MockCalled Update-Candidates-Cache 0
}
Reset-PGVM-Dir
}
}
Describe 'Check-JAVA-HOME' {
Context 'JAVA_HOME is set' {
Mock Get-Command
Mock Test-Path { $true } -parameterFilter { $Path -eq 'env:Java_HOME' }
Check-JAVA-HOME
It "changes nothing" {
Assert-MockCalled Get-Command 0
}
}
Context 'JAVA_HOME is not set but javac is on path' {
$backupJAVAHOME = [Environment]::GetEnvironmentVariable('JAVA_HOME')
Mock Test-Path { $false } -parameterFilter { $Path -eq 'env:Java_HOME' }
Mock Get-Command { New-Object PSObject -Property @{ Path = (Get-Item 'C:\Windows\explorer.exe') } } -parameterFilter { $Name -eq 'javac' }
$expectedNewJAVAHOME = 'C:\'
Check-JAVA-HOME
It "sets JAVA_HOME to javac parent" {
[Environment]::GetEnvironmentVariable('JAVA_HOME') | Should Be $expectedNewJAVAHOME
}
[Environment]::SetEnvironmentVariable('JAVA_HOME', $backupJAVAHOME)
}
Context 'JAVA_HOME is not set and javax is not on path' {
Mock Test-Path { $false } -parameterFilter { $Path -eq 'env:Java_HOME' }
Mock Get-Command { throw 'error' } -parameterFilter { $Name -eq 'javac' }
It "throws an error" {
{ Check-JAVA-HOME } | Should Throw
}
}
}