Skip to content

Commit aad64f0

Browse files
committed
Powershell: spec fixes
1 parent de2783e commit aad64f0

File tree

1 file changed

+38
-55
lines changed

1 file changed

+38
-55
lines changed

modules/BOSH.Sysprep/BOSH.Sysprep.Tests.ps1

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
BeforeAll {
22
Import-Module ./BOSH.Sysprep.psm1
33
Import-Module ../BOSH.Utils/BOSH.Utils.psm1
4+
Import-Module ../BOSH.Agent/BOSH.Agent.psm1
45

6+
7+
InModuleScope BOSH.Sysprep {
8+
function GCESysprep {} # See: https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image
9+
Mock GCESysprep {}
10+
}
511
function New-TempDir
612
{
713
$parent = [System.IO.Path]::GetTempPath()
@@ -20,11 +26,11 @@ Describe "BOSH.Sysprep" {
2026
Mock -ModuleName BOSH.Sysprep Stop-Computer { }
2127
Mock -ModuleName BOSH.Sysprep Start-Process { }
2228

23-
Mock -ModuleName BOSH.Sysprep -CommandName Test-Path -ParameterFilter {
24-
if ($Path -eq "C:\Windows\LGPO.exe")
25-
{
26-
return $True
27-
}
29+
Mock -ModuleName BOSH.Sysprep Get-OSVersion { "windows2019" }
30+
31+
$lgpoExists = $True
32+
Mock -ModuleName BOSH.Sysprep Test-Path { $lgpoExists } -ParameterFilter {
33+
$Path -eq "C:\Windows\LGPO.exe"
2834
}
2935
}
3036

@@ -35,6 +41,10 @@ Describe "BOSH.Sysprep" {
3541
}
3642

3743
Context "when provided an invalid Iaas" {
44+
BeforeEach {
45+
Mock -ModuleName BOSH.Sysprep -CommandName Set-NTP-Max-PhaseCorrection-Values { }
46+
}
47+
3848
It "throws" {
3949
{ Invoke-Sysprep -IaaS "OpenShift" -SkipLGPO -OsVersion "windows2019" } | Should -Throw "Invalid IaaS 'OpenShift' supported platforms are: AWS, Azure, GCP and Vsphere"
4050
}
@@ -60,42 +70,31 @@ Describe "BOSH.Sysprep" {
6070
}
6171

6272
Describe "LGPO" {
63-
Context "when OS is windows2019" {
64-
BeforeEach {
65-
Mock Get-OSVersion { "windows2019" } -ModuleName Bosh.Sysprep
66-
}
73+
It "enables local security policy with 'cis-merge-2019'" {
74+
$ExpectedPath = Join-Path $PSScriptRoot "cis-merge-2019"
75+
{ Invoke-Sysprep -Iaas "aws" } | Should -Not -Throw
6776

68-
It "enables local security policy with 'cis-merge-2019'" {
69-
$ExpectedPath = Join-Path $PSScriptRoot "cis-merge-2019"
70-
{ Invoke-Sysprep -Iaas "aws" } | Should -Not -Throw
71-
72-
Should -Invoke -ModuleName BOSH.Sysprep `
77+
Should -Invoke -ModuleName BOSH.Sysprep `
7378
-CommandName Enable-LocalSecurityPolicy -Times 1 -ParameterFilter {
74-
$PolicySource -eq $ExpectedPath
75-
}
79+
$PolicySource -eq $ExpectedPath
7680
}
81+
}
7782

78-
Context "when '-SkipLGPO' is set" {
79-
It "skips local policy update if -SkipLGPO is set" {
80-
{ Invoke-Sysprep -Iaas "aws" -SkipLGPO } | Should -Not -Throw
83+
Context "when '-SkipLGPO' is set" {
84+
It "skips local policy update if -SkipLGPO is set" {
85+
{ Invoke-Sysprep -Iaas "aws" -SkipLGPO } | Should -Not -Throw
8186

82-
Should -Invoke -ModuleName BOSH.Sysprep -CommandName Enable-LocalSecurityPolicy -Times 0
83-
}
87+
Should -Invoke -ModuleName BOSH.Sysprep -CommandName Enable-LocalSecurityPolicy -Times 0
8488
}
89+
}
8590

86-
Context "if LGPO.exe is not found" {
87-
BeforeEach {
88-
Mock -ModuleName BOSH.Sysprep -CommandName Test-Path -ParameterFilter {
89-
if ($Path -eq "C:\Windows\LGPO.exe")
90-
{
91-
return $True
92-
}
93-
}
94-
}
91+
Context "if LGPO.exe is not found" {
92+
BeforeEach {
93+
$lgpoExists = $False
94+
}
9595

96-
It "throws an error" {
97-
{ Invoke-Sysprep -Iaas "aws" -SkipLGPO } | Should -Throw
98-
}
96+
It "throws an error" {
97+
{ Invoke-Sysprep -Iaas "aws" } | Should -Throw
9998
}
10099
}
101100
}
@@ -106,6 +105,7 @@ Describe "BOSH.Sysprep" {
106105
Mock -ModuleName BOSH.Sysprep Set-NTP-Max-PhaseCorrection-Values { }
107106
Mock -ModuleName BOSH.Sysprep Enable-LocalSecurityPolicy { }
108107

108+
Mock -ModuleName BOSH.Sysprep Disable-AgentService { }
109109
Mock -ModuleName BOSH.Sysprep Create-GCP-UnattendXML { }
110110
Mock -ModuleName BOSH.Sysprep GCESysprep { }
111111
}
@@ -125,10 +125,6 @@ Describe "BOSH.Sysprep" {
125125

126126
Describe "LGPO" {
127127
Context "when OS is windows2019" {
128-
BeforeEach {
129-
Mock Get-OSVersion { "windows2019" } -ModuleName Bosh.Sysprep
130-
}
131-
132128
It "enables local security policy with 'cis-merge-2019'" {
133129
$ExpectedPath = Join-Path $PSScriptRoot "cis-merge-2019"
134130
{ Invoke-Sysprep -Iaas "gcp" } | Should -Not -Throw
@@ -149,16 +145,11 @@ Describe "BOSH.Sysprep" {
149145

150146
Context "if LGPO.exe is not found" {
151147
BeforeEach {
152-
Mock -ModuleName BOSH.Sysprep -CommandName Test-Path -ParameterFilter {
153-
if ($Path -eq "C:\Windows\LGPO.exe")
154-
{
155-
return $True
156-
}
157-
}
148+
$lgpoExists = $False
158149
}
159150

160151
It "throws an error" {
161-
{ Invoke-Sysprep -Iaas "gcp" -SkipLGPO } | Should -Throw
152+
{ Invoke-Sysprep -Iaas "gcp" } | Should -Throw
162153
}
163154
}
164155
}
@@ -170,6 +161,7 @@ Describe "BOSH.Sysprep" {
170161
Mock -ModuleName BOSH.Sysprep Set-NTP-Max-PhaseCorrection-Values { }
171162
Mock -ModuleName BOSH.Sysprep Enable-LocalSecurityPolicy { }
172163

164+
Mock -ModuleName BOSH.Sysprep Disable-AgentService { }
173165
Mock -ModuleName BOSH.Sysprep Create-vSphere-Unattend { }
174166
Mock -ModuleName BOSH.Sysprep Invoke-Expression { }
175167
}
@@ -198,10 +190,6 @@ Describe "BOSH.Sysprep" {
198190

199191
Describe "LGPO" {
200192
Context "when OS is windows2019" {
201-
BeforeEach {
202-
Mock Get-OSVersion { "windows2019" } -ModuleName Bosh.Sysprep
203-
}
204-
205193
It "enables local security policy with 'cis-merge-2019'" {
206194
$ExpectedPath = Join-Path $PSScriptRoot "cis-merge-2019"
207195
{ Invoke-Sysprep -Iaas "vsphere" } | Should -Not -Throw
@@ -222,16 +210,11 @@ Describe "BOSH.Sysprep" {
222210

223211
Context "if LGPO.exe is not found" {
224212
BeforeEach {
225-
Mock -ModuleName BOSH.Sysprep -CommandName Test-Path -ParameterFilter {
226-
if ($Path -eq "C:\Windows\LGPO.exe")
227-
{
228-
return $True
229-
}
230-
}
213+
$lgpoExists = $False
231214
}
232215

233216
It "throws an error" {
234-
{ Invoke-Sysprep -Iaas "vsphere" -SkipLGPO } | Should -Throw
217+
{ Invoke-Sysprep -Iaas "vsphere" } | Should -Throw
235218
}
236219
}
237220
}

0 commit comments

Comments
 (0)