Skip to content

Commit 48c1af4

Browse files
committed
revert changes to existing failing tests
1 parent 2496d78 commit 48c1af4

4 files changed

Lines changed: 64 additions & 28 deletions

File tree

step-templates/tests/Invoke-PesterTests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ function Unpack-Scripts-Under-Test {
4545
-TestRoot $thisFolder `
4646
-Filter $Filter `
4747
-BeforeRun ${function:Unpack-Scripts-Under-Test} `
48-
-UsePassThruFailureCheck
48+
-UsePassThruFailureCheck `
49+
-PreferredPesterVersion "3.4.0" `
50+
-SuiteName "step-templates"

step-templates/tests/windows-scheduled-task-create.ScriptBody.Tests.ps1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Describe "Create-ScheduledTask" {
1212
It "Should invoke a matching command line" {
1313
Create-ScheduledTask;
1414
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
15-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
16-
$expectedArgs = @( "/Create", "/RU", "`"`"", "/SC", "", "/TN", "`"`"", "/TR", "`"''`"", "/F" )
15+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
16+
$expectedArgs = @( "/Create", "/RU", "", "/SC", "", "/TN", "`"`"", "/TR", "''", "/F" )
1717
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
1818
#Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
1919
#Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));
@@ -39,8 +39,8 @@ Describe "Create-ScheduledTask" {
3939
-Duration "" `
4040
-StartNewTaskNow "";
4141
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
42-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
43-
$expectedArgs = @( "/Create", "/RU", "`"`"", "/SC", "", "/TN", "`"`"", "/TR", "`"''`"", "/F" )
42+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
43+
$expectedArgs = @( "/Create", "/RU", "", "/SC", "", "/TN", "`"`"", "/TR", "''", "/F" )
4444
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
4545
#Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
4646
#Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));
@@ -66,8 +66,8 @@ Describe "Create-ScheduledTask" {
6666
-Duration "myDuration"`
6767
-StartNewTaskNow "myStartNewTaskNow";
6868
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
69-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
70-
$expectedArgs = @( "/Create", "/RU", "`"myRunAsUser`"", "/RP `"myRunAsPassword`"", "/SC", "mySchedule", "/RI", "myInterval", "/D", "myDays", "/TN", "`"myTaskName`"", "/TR", "`"'myTaskRun' myArguments`"", "/ST", "myStartTime", "/DU", "myDuration", "/SD", "myStartDate", "/F", "/RL", "HIGHEST" )
69+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
70+
$expectedArgs = @( "/Create", "/RU", "myRunAsUser", "/RP", "myRunAsPassword", "/SC", "mySchedule", "/D", "myDays", "/TN", "`"myTaskname`"", "/TR", "`"'myTaskRun' 'myArguments'`"", "/ST", "myStartTime", "/DU", "myDuration", "/SD", "myStartDate", "/F", "/RL", "HIGHEST" )
7171
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
7272
#Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
7373
#Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));
@@ -93,8 +93,8 @@ Describe "Create-ScheduledTask" {
9393
-Duration "" `
9494
-StartNewTaskNow "";
9595
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
96-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
97-
$expectedArgs = @( "/Create", "/RU", "`"`"", "/SC", "", "/TN", "`"`"", "/TR", "`"'myTaskRun'`"", "/F" )
96+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
97+
$expectedArgs = @( "/Create", "/RU", "", "/SC", "", "/TN", "`"`"", "/TR", "'myTaskRun'", "/F" )
9898
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
9999
#Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
100100
#Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));
@@ -120,8 +120,8 @@ Describe "Create-ScheduledTask" {
120120
-Duration "" `
121121
-StartNewTaskNow "";
122122
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
123-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
124-
$expectedArgs = @( "/Create", "/RU", "`"`"", "/SC", "", "/TN", "`"`"", "/TR", "`"'myTaskRun' myArguments`"", "/F" )
123+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
124+
$expectedArgs = @( "/Create", "/RU", "", "/SC", "", "/TN", "`"`"", "/TR", "`"'myTaskRun' 'myArguments'`"", "/F" )
125125
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
126126
#Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
127127
#Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));
@@ -132,7 +132,7 @@ Describe "Create-ScheduledTask" {
132132
}
133133

134134
Context "WEEKDAYS schedule parameter specified" {
135-
It "WEEKDAYS is passed through when no days are specified" {
135+
It "WEEKDAYS gets replaced with WEEKLY" {
136136
Create-ScheduledTask -TaskName "" `
137137
-RunAsUser "" `
138138
-RunAsPassword "" `
@@ -147,8 +147,8 @@ Describe "Create-ScheduledTask" {
147147
-Duration "" `
148148
-StartNewTaskNow "";
149149
Assert-MockCalled Invoke-CommandLine -Times 1 -ParameterFilter {
150-
$expectedCmd = "$($env:SystemRoot)\System32\schtasks.exe"
151-
$expectedArgs = @( "/Create", "/RU", "`"`"", "/SC", "WEEKDAYS", "/TN", "`"`"", "/TR", "`"''`"", "/F" )
150+
$expectedCmd = "C:\Windows\System32\schtasks.exe"
151+
$expectedArgs = @( "/Create", "/RU", "", "/SC", "WEEKLY", "/TN", "`"`"", "/TR", "''", "/D", "MON,TUE,WED,THU,FRI", "/F" )
152152
$argDiffs = Compare-Object $ArgumentList $expectedArgs -SyncWindow 0;
153153
Write-Host ("expected = " + ($expectedArgs | % { "[$($_)]"}));
154154
Write-Host ("actual = " + ($ArgumentList | % { "[$($_)]"}));

tools/Invoke-SharedPesterTests.ps1

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ param(
44
[string] $Filter = "*",
55
[scriptblock] $BeforeRun,
66
[string[]] $ImportModules = @(),
7-
[switch] $UsePassThruFailureCheck
7+
[switch] $UsePassThruFailureCheck,
8+
[string] $PreferredPesterVersion,
9+
[string] $SuiteName = "tests"
810
)
911

1012
$ErrorActionPreference = "Stop";
@@ -15,30 +17,58 @@ $repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
1517
$originalSystemRoot = $env:SystemRoot
1618
$originalTemp = $env:TEMP
1719

18-
function Get-PesterModulePath {
20+
function Get-PesterModuleSpec {
1921
$packagesFolder = Join-Path $repoRoot "packages"
20-
$localPesterPaths = @(
21-
(Join-Path $packagesFolder "Pester" "tools" "Pester"),
22-
(Join-Path $packagesFolder "Pester.3.4.3" "tools" "Pester")
23-
)
22+
$attempts = @()
23+
$localPesterPaths = @()
24+
25+
if ($PreferredPesterVersion) {
26+
$localPesterPaths += (Join-Path $packagesFolder ("Pester.{0}" -f $PreferredPesterVersion) "tools" "Pester")
27+
}
28+
$localPesterPaths += (Join-Path $packagesFolder "Pester" "tools" "Pester")
2429

25-
foreach ($localPesterPath in $localPesterPaths) {
30+
foreach ($localPesterPath in $localPesterPaths | Select-Object -Unique) {
31+
$attempts += $localPesterPath
2632
if (Test-Path -Path $localPesterPath) {
2733
$localManifestPath = Join-Path $localPesterPath "Pester.psd1"
34+
$modulePath = $localPesterPath
2835
if (Test-Path -Path $localManifestPath) {
29-
return $localManifestPath
36+
$modulePath = $localManifestPath
3037
}
3138

32-
return $localPesterPath
39+
$module = Test-ModuleManifest -Path $modulePath -ErrorAction Stop
40+
if ($module.Version.Major -eq 3 -and ((-not $PreferredPesterVersion) -or $module.Version -eq [version]$PreferredPesterVersion)) {
41+
return [pscustomobject]@{
42+
ModulePath = $module.Path
43+
Version = $module.Version.ToString()
44+
Source = "repository packages"
45+
}
46+
}
3347
}
3448
}
3549

36-
$globalPester = Get-Module -ListAvailable Pester | Where-Object { $_.Version -eq [version]"3.4.3" } | Select-Object -First 1
50+
$availablePesterModules = @(Get-Module -ListAvailable Pester | Sort-Object Version -Descending)
51+
$globalPester = $null
52+
53+
if ($PreferredPesterVersion) {
54+
$globalPester = $availablePesterModules | Where-Object { $_.Version -eq [version]$PreferredPesterVersion } | Select-Object -First 1
55+
}
56+
57+
if (-not $globalPester) {
58+
$globalPester = $availablePesterModules | Where-Object { $_.Version.Major -eq 3 } | Select-Object -First 1
59+
}
60+
3761
if ($globalPester) {
38-
return $globalPester.Path
62+
return [pscustomobject]@{
63+
ModulePath = $globalPester.Path
64+
Version = $globalPester.Version.ToString()
65+
Source = "installed modules"
66+
}
3967
}
4068

41-
throw "Pester 3.4.3 was not found in the repository packages folder or installed modules."
69+
$preferredVersionMessage = if ($PreferredPesterVersion) { "preferred version $PreferredPesterVersion" } else { "a Pester 3.x version" }
70+
$attemptedPathsMessage = if ($attempts.Count -gt 0) { " Tried package paths: $($attempts -join ', ')." } else { "" }
71+
throw "Pester $preferredVersionMessage for suite '$SuiteName' was not found in the repository packages folder or installed modules.$attemptedPathsMessage"
4272
}
4373

4474
function Invoke-SelectedTests {
@@ -93,7 +123,9 @@ try {
93123
}
94124
}
95125

96-
Import-Module -Name (Get-PesterModulePath) -RequiredVersion 3.4.3 -ErrorAction Stop
126+
$pesterModule = Get-PesterModuleSpec
127+
Write-Host "Using Pester module version $($pesterModule.Version) from $($pesterModule.Source)."
128+
Import-Module -Name $pesterModule.ModulePath -RequiredVersion $pesterModule.Version -ErrorAction Stop
97129
Invoke-SelectedTests -TestFiles $testFiles
98130
} finally {
99131
$env:SystemRoot = $originalSystemRoot

tools/StepTemplatePacker/tests/Invoke-PesterTests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ $sharedRunner = Join-Path $repoRoot "tools" "Invoke-SharedPesterTests.ps1";
1414
& $sharedRunner `
1515
-TestRoot $thisFolder `
1616
-Filter $Filter `
17-
-ImportModules @($packer);
17+
-ImportModules @($packer) `
18+
-PreferredPesterVersion "3.4.3" `
19+
-SuiteName "StepTemplatePacker";

0 commit comments

Comments
 (0)