Skip to content

Commit 1d9dfb0

Browse files
committed
WIP Pester automation helper test
1 parent 86312f0 commit 1d9dfb0

File tree

6 files changed

+80
-65
lines changed

6 files changed

+80
-65
lines changed

ci/pipelines/stemcells-windows-2019.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ resources:
160160
type: git
161161
source:
162162
uri: https://github.com/cloudfoundry/windows-utilities-release.git
163-
- name: pester
164-
type: git
165-
source:
166-
uri: https://github.com/pester/Pester.git
167-
tag_filter: 4.4.0
168163
- name: bosh-windows-acceptance-tests-src-out
169164
type: git
170165
source:
@@ -686,9 +681,17 @@ jobs:
686681
- get: bosh-windows-stemcell-builder-ci
687682
- get: stemcell-builder
688683
trigger: true
689-
- task: test-units-bosh-psmodules
690-
file: bosh-windows-stemcell-builder-ci/ci/tasks/test-units-bosh-psmodules/task.yml
691-
tags: [windows-nimbus]
684+
- in_parallel:
685+
- task: test-units-bosh-psmodules
686+
file: bosh-windows-stemcell-builder-ci/ci/tasks/test-units-bosh-psmodules/task.yml
687+
tags: [windows-nimbus]
688+
params:
689+
MODULES_DIR: modules
690+
- task: test-units-bosh-psmodules-stembuild
691+
file: bosh-windows-stemcell-builder-ci/ci/tasks/test-units-bosh-psmodules/task.yml
692+
tags: [windows-nimbus]
693+
params:
694+
MODULES_DIR: stembuild/modules
692695
- name: test-stemcell-builder
693696
serial: true
694697
plan:
@@ -814,7 +817,6 @@ jobs:
814817
steps:
815818
- get: bosh-windows-stemcell-builder-ci
816819
- get: bosh-windows-stemcell-builder-ci-image
817-
- get: pester
818820
- get: open-ssh
819821
resource: openssh-release
820822
- get: stemcell-builder
@@ -924,7 +926,6 @@ jobs:
924926
steps:
925927
- get: bosh-windows-stemcell-builder-ci
926928
- get: bosh-windows-stemcell-builder-ci-image
927-
- get: pester
928929
- get: open-ssh
929930
resource: openssh-release
930931
- get: stemcell-builder

ci/tasks/test-units-bosh-psmodules/run.ps1

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ function New-TemporaryDirectory {
33
$name = (New-Guid).ToString("N")
44
New-Item -ItemType Directory -Path (Join-Path $tmp $name)
55
}
6-
76
$moduleDir = New-TemporaryDirectory
87
$pesterModule = Find-Module -Name Pester -MaximumVersion "5.9999" -MinimumVersion "5.0"
98
$pesterModule | Save-Module -Path $moduleDir
10-
119
Import-Module "$moduleDir\Pester\$($pesterModule.Version)\Pester.psm1"
1210

1311
$status = (Get-Service -Name "wuauserv").Status
@@ -17,7 +15,7 @@ $startupType = Get-Service "wuauserv" | Select-Object -ExpandProperty StartType
1715

1816
$result = 0
1917

20-
$testModules = Get-ChildItem "./bosh-psmodules-repo/modules/" -recurse | where {$_.name -match ".*.Tests.ps1"} | foreach {$_.DirectoryName}
18+
$testModules = Get-ChildItem "./stemcell-builder/$env:MODULES_DIR" -recurse | where {$_.name -match ".*.Tests.ps1"} | foreach {$_.DirectoryName}
2119
foreach ($module in $testModules) {
2220
Write-Host "Testing: $module"
2321
Push-Location "$module"
@@ -33,6 +31,5 @@ foreach ($module in $testModules) {
3331
Pop-Location
3432
}
3533

36-
echo "Failed Tests: $result"
34+
echo "Failed Test Count: $result"
3735
exit $result
38-

ci/tasks/test-units-bosh-psmodules/task.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
- name: bosh-windows-stemcell-builder-ci
66
- name: stemcell-builder
77

8+
params:
9+
MODULES_DIR:
10+
811
run:
912
path: powershell
1013
args:

ci/tasks/test-units-stemcell-automation/task.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@ platform: windows
33
inputs:
44
- name: bosh-windows-stemcell-builder-ci
55
- name: stemcell-builder
6-
- name: pester
76

87
run:
98
path: powershell
109
args:
1110
- "-Command"
12-
- "& {
13-
Import-Module ./bosh-windows-stemcell-builder-ci/ci/common-scripts/setup-windows-container.psm1;
14-
Set-TmpDir;
15-
Import-Module ./Pester/pester.psm1;
16-
pushd stemcell-builder/stembuild/stemcell-automation;
17-
$result=Invoke-Pester -PassThru;
18-
popd;
19-
Write-Host \"Failed Tests:\"$result.FailedCount;
20-
exit $result.FailedCount
21-
}"
11+
- |
12+
& {
13+
function New-TemporaryDirectory {
14+
$tmp = [System.IO.Path]::GetTempPath() # Not $env:TEMP, see https://stackoverflow.com/a/946017
15+
$name = (New-Guid).ToString("N")
16+
New-Item -ItemType Directory -Path (Join-Path $tmp $name)
17+
}
18+
$moduleDir = New-TemporaryDirectory
19+
$pesterModule = Find-Module -Name Pester -MaximumVersion "5.9999" -MinimumVersion "5.0"
20+
$pesterModule | Save-Module -Path $moduleDir
21+
Import-Module "$moduleDir\Pester\$($pesterModule.Version)\Pester.psm1"
22+
23+
Import-Module ./bosh-windows-stemcell-builder-ci/ci/common-scripts/setup-windows-container.psm1;
24+
Set-TmpDir;
25+
pushd stemcell-builder/stembuild/stemcell-automation;
26+
$result=Invoke-Pester -PassThru;
27+
popd;
28+
29+
Write-Host "Failed Test Count:"$result.FailedCount;
30+
exit $result.FailedCount
31+
}

stembuild/modules/BOSH.CFCell/BOSH.CFCell.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ BeforeAll {
88

99
Describe "Protect-CFCell" {
1010
BeforeEach {
11+
Mock -ModuleName BOSH.CFCell Write-Log { }
12+
1113
$oldWinRMStatus = (Get-Service winrm).Status
1214
$oldWinRMStartMode = ( Get-Service winrm ).StartType
1315

stembuild/stemcell-automation/AutomationHelpers.Tests.ps1

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
# We import module BOSH.SSH to ensure that we get the Install-SSHD function it defines. Starting with
22
# OpenSSH 9.1, there is a conflicting install-sshd.ps1 script that takes precedence instead if you do
33
# not load the module.
4-
Import-Module -Name BOSH.SSH
5-
. ./AutomationHelpers.ps1
4+
BeforeAll {
5+
Import-Module -Name BOSH.SSH
6+
. ./AutomationHelpers.ps1
7+
8+
function GenerateDepJson
9+
{
10+
param ([parameter(Mandatory = $true)] [string]$file1Sha,
11+
[parameter(Mandatory = $true)] [string]$file2Sha,
12+
[parameter(Mandatory = $true)] [string]$file3Sha
13+
)
14+
15+
return "{""file1.zip"":{""sha"":""$file1Sha"",""version"":""1.0""},""file2.zip"":{""sha"":""$file2Sha"",""version"":""1.0-alpha""},""file3.exe"":{""sha"":""$file3Sha"",""version"":""3.0""}}"
16+
}
17+
18+
function CreateFakeOpenSSHZip
19+
{
20+
param([string]$dir, [string]$installScriptSpyStatus, [string]$fakeZipPath)
21+
22+
mkdir "$dir\OpenSSH-Win64"
23+
$installSpyBehavior = "echo installed > $installScriptSpyStatus"
24+
echo $installSpyBehavior > "$dir\OpenSSH-Win64\install-sshd.ps1"
25+
echo "fake sshd" > "$dir\OpenSSH-Win64\sshd.exe"
26+
27+
Compress-Archive -Force -Path "$dir\OpenSSH-Win64" -DestinationPath $fakeZipPath
28+
}
29+
30+
function CreateFakeLGPOZip
31+
{
32+
param([string]$dir, [string]$fakeZipPath)
33+
34+
New-Item -ItemType Directory "$dir\LGPO\LGPO_30"
35+
echo "fake lgpo" > "$dir\LGPO\LGPO_30\LGPO.exe"
36+
37+
Compress-Archive -Force -Path "$dir\LGPO\*" -DestinationPath $fakeZipPath
38+
}
39+
40+
function Get-WuCerts { }
41+
42+
}
643

744
Describe "Setup" {
845
BeforeEach {
@@ -233,7 +270,6 @@ Describe "InstallCFFeatures" {
233270
}
234271
}
235272

236-
237273
Describe "InstallCFCell" {
238274
It "executes the Protect-CFCell powershell cmdlet" {
239275
Mock Protect-CFCell { }
@@ -517,18 +553,10 @@ Describe "Is-Special" {
517553
}
518554
}
519555

520-
function GenerateDepJson
521-
{
522-
param ([parameter(Mandatory = $true)] [string]$file1Sha,
523-
[parameter(Mandatory = $true)] [string]$file2Sha,
524-
[parameter(Mandatory = $true)] [string]$file3Sha
525-
)
526-
527-
return "{""file1.zip"":{""sha"":""$file1Sha"",""version"":""1.0""},""file2.zip"":{""sha"":""$file2Sha"",""version"":""1.0-alpha""},""file3.exe"":{""sha"":""$file3Sha"",""version"":""3.0""}}"
528-
}
529-
530556
Describe "Check-Dependencies" {
531557
BeforeEach {
558+
Mock Check-Dependencies { }
559+
532560
Mock Write-Log { }
533561

534562
$file1Hash = @{
@@ -559,7 +587,6 @@ Describe "Check-Dependencies" {
559587
Mock ConvertFrom-Json { throw "Invalid JSON primitive: bad-json-format" } -ParameterFilter { $InputObject -match "bad-json-format" }
560588
}
561589

562-
563590
It "successfully checks all required files are available and have the correct SHAs" {
564591
Mock Get-Content { GenerateDepJson "hashOne" "hashTwo" "hashThree" }
565592

@@ -822,28 +849,6 @@ Describe "Install-SecurityPoliciesAndRegistries" {
822849

823850
}
824851

825-
function CreateFakeOpenSSHZip
826-
{
827-
param([string]$dir, [string]$installScriptSpyStatus, [string]$fakeZipPath)
828-
829-
mkdir "$dir\OpenSSH-Win64"
830-
$installSpyBehavior = "echo installed > $installScriptSpyStatus"
831-
echo $installSpyBehavior > "$dir\OpenSSH-Win64\install-sshd.ps1"
832-
echo "fake sshd" > "$dir\OpenSSH-Win64\sshd.exe"
833-
834-
Compress-Archive -Force -Path "$dir\OpenSSH-Win64" -DestinationPath $fakeZipPath
835-
}
836-
837-
function CreateFakeLGPOZip
838-
{
839-
param([string]$dir, [string]$fakeZipPath)
840-
841-
New-Item -ItemType Directory "$dir\LGPO\LGPO_30"
842-
echo "fake lgpo" > "$dir\LGPO\LGPO_30\LGPO.exe"
843-
844-
Compress-Archive -Force -Path "$dir\LGPO\*" -DestinationPath $fakeZipPath
845-
}
846-
847852
Describe "Enable-SSHD" {
848853
BeforeEach {
849854
Mock Set-Service { }
@@ -1021,9 +1026,6 @@ Describe "Extract-LGPO" {
10211026
}
10221027
}
10231028

1024-
function Get-WuCerts {
1025-
}
1026-
10271029
Describe "Install-WUCerts" {
10281030
It "executes the Get-WUCerts powershell cmdlet" {
10291031
Mock Get-WUCerts { }

0 commit comments

Comments
 (0)