This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProvisionVM.Tests.ps1
113 lines (85 loc) · 4.06 KB
/
ProvisionVM.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
. ./ProvisionVM.ps1
Describe "ProvisionVM" {
BeforeEach {
[System.Collections.ArrayList]$provisionerCalls = @()
Mock InstallCFFeatures { $provisionerCalls.Add("InstallCFFeatures") }
Mock CopyPSModules { $provisionerCalls.Add("CopyPSModules") }
Mock InstallOpenSSH { $provisionerCalls.Add("InstallOpenSSH") }
Mock InstallBoshAgent { $provisionerCalls.Add("InstallBoshAgent") }
Mock Enable-SSHD { $provisionerCalls.Add("Enable-SSHD") }
Mock Install-SecurityPoliciesAndRegistries { $provisionerCalls.Add("Install-SecurityPoliciesAndRegistries") }
Mock Extract-LGPO { $provisionerCalls.Add("Extract-LGPO") }
Mock Enable-HyperV { $provisionerCalls.Add("Enable-HyperV") }
Mock Install-WUCerts { $provisionerCalls.Add("Install-WUCerts") }
Mock Create-VersionFile { $provisionerCalls.Add("Create-VersionFile") }
if (!(Get-Command "Restart-Computer" -errorAction SilentlyContinue))
{
function Restart-Computer() {
throw "what is happening I should never be invoked"
}
}
Mock Restart-Computer { $provisionerCalls.Add("Restart-Computer") }
}
It "installs CFFeatures" {
ProvisionVM
Assert-MockCalled -CommandName InstallCFFeatures
}
It "enables Hyper-V when possible" {
ProvisionVM
Assert-MockCalled -CommandName Enable-HyperV
}
It "copy PSModules is the first provisioner called" {
ProvisionVM
Assert-MockCalled -CommandName CopyPSModules
$provisionerCalls.IndexOf("CopyPSModules") | Should -Be 0
}
It "installs BoshAgent" {
ProvisionVM
Assert-MockCalled -CommandName InstallBoshAgent
}
It "installs OpenSSH before enabling SSH" {
ProvisionVM
Assert-MockCalled -CommandName InstallOpenSSH
$provisionerCalls.IndexOf("InstallOpenSSH") | Should -BeGreaterOrEqual 0
$provisionerCalls.IndexOf("InstallOpenSSH") | Should -BeLessThan $provisionerCalls.IndexOf("Enable-SSHD")
}
It "enables SSHD" {
ProvisionVM
Assert-MockCalled -CommandName Enable-SSHD
}
It "installs SecurityPoliciesAndRegistries after extracting LGPO" {
ProvisionVM
Assert-MockCalled -CommandName Install-SecurityPoliciesAndRegistries
$provisionerCalls.IndexOf("Extract-LGPO") | Should -BeGreaterOrEqual 0
$provisionerCalls.IndexOf("Extract-LGPO") | Should -BeLessThan $provisionerCalls.IndexOf("Install-SecurityPoliciesAndRegistries")
}
It "extracts LGPO before enabling SSH" {
ProvisionVM
Assert-MockCalled -CommandName Extract-LGPO
$provisionerCalls.IndexOf("Extract-LGPO") | Should -BeGreaterOrEqual 0
$provisionerCalls.IndexOf("Extract-LGPO") | Should -BeLessThan $provisionerCalls.IndexOf("Enable-SSHD")
}
It "fails gracefully when Install-WUCerts helper fails" {
Mock Install-WUCerts { throw "Something went wrong trying to Install-WUCerts" }
Mock Write-Log { }
Mock Write-Warning { }
{ ProvisionVM } | Should -Not -Throw
Assert-MockCalled Install-WUCerts -Times 1 -Scope It
Assert-MockCalled Write-Log -Times 1 -Scope It -ParameterFilter {$Message -eq "Something went wrong trying to Install-WUCerts" }
Assert-MockCalled Write-Warning -Times 1 -Scope It -ParameterFilter {$Message -eq "This should not impact the successful execution of stembuild construct. If the root certificates are out of date, Diego cells running on VMs built off of this stemcell may not be able to make outbound network connections." }
}
It "installs WU certs" {
ProvisionVM
Assert-MockCalled -CommandName Install-WUCerts
}
It "creates a version file" {
ProvisionVM
Assert-MockCalled -CommandName Create-VersionFile
}
It "restarts as the last command" {
ProvisionVM
Assert-MockCalled -CommandName Restart-Computer
$lastIndex = $provisionerCalls.Count - 1
$provisionerCalls.IndexOf("Restart-Computer") | Should -Be $lastIndex
}
}