Pester test formatting cleanups

This commit is contained in:
Andrew Schwartzmeyer committed 2016-03-04 14:38:01 -08:00
1 parent 7673c4e90f
commit de6a452f63
12 files changed
+204 -205

No files matched your search

-1
View File
@@ -13,7 +13,6 @@ Describe "Export-Alias" {
It "Should be able to create a file in the specified location"{
Export-Alias $fulltestpath
Test-Path $fulltestpath | Should be $true
}
+1 -1
View File
@@ -10,7 +10,7 @@
}
It "Should be able to use the format flag" {
# You would think that one could use simple loops here, but apparently powershell in windows returns different values in loops
# You would think that one could use simple loops here, but apparently powershell in Windows returns different values in loops
(Get-Date -Format d).Contains("/") | Should be $true
(Get-Date -Format D).Contains(",") | Should be $true
+3 -3
View File
@@ -1,7 +1,7 @@
Describe "Get-Event" {
BeforeEach {
( New-Event -SourceIdentifier PesterTestEvent -sender windows.timer -messagedata "PesterTestMessage" )
( New-Event -SourceIdentifier PesterTestEvent -sender Windows.timer -messagedata "PesterTestMessage" )
}
AfterEach {
@@ -25,8 +25,8 @@ Describe "Get-Event" {
{ (Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage" }
}
It "Should return Sender as windows.timer" {
{ (Get-Event -SourceIdentifier PesterTimer).Sender | Should be windows.timer }
It "Should return Sender as Windows.timer" {
{ (Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer }
}
}
@@ -1,8 +1,8 @@
Describe "Get-EventSubscriber" {
AfterEach {
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
}
AfterEach {
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
}
Context "Check return type of Get-EventSubscriber" {
+49 -49
View File
@@ -1,49 +1,49 @@
Describe "Get-FileHash" {
New-Variable testDocument -Value (Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testablescript.ps1) -Scope Global -Force
# The MACTripleDES and RIPEMD160 algorithms are unsupported on Linux
$algorithms = @{"SHA1" ="01B865D143E07ECC875AB0EFC0A4429387FD0CF7";
"SHA256" = "4A6DA9F1C0827143BB19FC4B0F2A8057BC1DF55F6D1F62FA3B917BA458E8F570";
"SHA384" = "656215B6A07011E625206F43E57873F49AD7B36DFCABB70F6CDCE2303D7A603E55D052774D26F339A6D80A264340CB8C";
"SHA512" = "C688C33027D89ACAC920545471C8053D8F64A54E21D0415F1E03766DDCDA215420E74FAFD1DC399864C6B6B5723A3358BD337339906797A39090B02229BF31FE";
"MD5" = "7B09811D1631C9FD46B39D1D35522F0A";
}
Context "Cmdlet result tests" {
It "Should default to correct hash algorithm" {
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "SHA256"
}
It "Should be able to set the default hash algorithm" {
$PSDefaultParameterValues.add("Get-FileHash:Algorithm","MD5")
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "MD5"
$PSDefaultParameterValues.Remove("Get-FileHash:Algorithm")
}
It "Should list the path of the file under test" {
$result = Get-FileHash $testDocument
$result.Path | Should Be $testDocument
}
}
Context "Algorithm tests" {
It "Should be able to get the correct hash from each algorithm" {
foreach ( $algorithm in $algorithms.Keys)
{
$algorithmResult = Get-FileHash $testDocument -Algorithm $algorithm
$algorithmResult.Hash | Should Be $algorithms[$algorithm]
}
#MACTripleDES and RIPEMD160 are unsupported in the existing Pester tests from windows team
{ Get-FileHash $testDocument -Algorithm MACTripleDES } | Should Throw "Algorithm 'MACTripleDES' is not supported in this system."
{ Get-FileHash $testDocument -Algorithm RIPEMD160 } | Should Throw "Algorithm 'RIPEMD160' is not supported in this system."
}
}
}
Describe "Get-FileHash" {
New-Variable testDocument -Value (Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testablescript.ps1) -Scope Global -Force
# The MACTripleDES and RIPEMD160 algorithms are unsupported on Linux
$algorithms = @{"SHA1" ="01B865D143E07ECC875AB0EFC0A4429387FD0CF7";
"SHA256" = "4A6DA9F1C0827143BB19FC4B0F2A8057BC1DF55F6D1F62FA3B917BA458E8F570";
"SHA384" = "656215B6A07011E625206F43E57873F49AD7B36DFCABB70F6CDCE2303D7A603E55D052774D26F339A6D80A264340CB8C";
"SHA512" = "C688C33027D89ACAC920545471C8053D8F64A54E21D0415F1E03766DDCDA215420E74FAFD1DC399864C6B6B5723A3358BD337339906797A39090B02229BF31FE";
"MD5" = "7B09811D1631C9FD46B39D1D35522F0A";
}
Context "Cmdlet result tests" {
It "Should default to correct hash algorithm" {
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "SHA256"
}
It "Should be able to set the default hash algorithm" {
$PSDefaultParameterValues.add("Get-FileHash:Algorithm","MD5")
$result = Get-FileHash $testDocument
$result.Algorithm | Should Be "MD5"
$PSDefaultParameterValues.Remove("Get-FileHash:Algorithm")
}
It "Should list the path of the file under test" {
$result = Get-FileHash $testDocument
$result.Path | Should Be $testDocument
}
}
Context "Algorithm tests" {
It "Should be able to get the correct hash from each algorithm" {
foreach ( $algorithm in $algorithms.Keys)
{
$algorithmResult = Get-FileHash $testDocument -Algorithm $algorithm
$algorithmResult.Hash | Should Be $algorithms[$algorithm]
}
#MACTripleDES and RIPEMD160 are unsupported in the existing Pester tests from Windows team
{ Get-FileHash $testDocument -Algorithm MACTripleDES } | Should Throw "Algorithm 'MACTripleDES' is not supported in this system."
{ Get-FileHash $testDocument -Algorithm RIPEMD160 } | Should Throw "Algorithm 'RIPEMD160' is not supported in this system."
}
}
}
+4 -4
View File
@@ -9,14 +9,14 @@ Describe "New-Event" {
Context "Check New-Event can register an event"{
It "Should return PesterTestMessage as the MessageData" {
(New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage")
(New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage")
(Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage"
Remove-Event -sourceidentifier PesterTimer
}
It "Should return Sender as windows.timer" {
(New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage")
(Get-Event -SourceIdentifier PesterTimer).Sender | Should be windows.timer
It "Should return Sender as Windows.timer" {
(New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage")
(Get-Event -SourceIdentifier PesterTimer).Sender | Should be Windows.timer
Remove-Event -sourceIdentifier PesterTimer
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ Describe "New-Item" {
}
It "Should not create a file when the Name switch is not used and only a directory specified" {
#errorAction used because permissions issue in windows
#errorAction used because permissions issue in Windows
New-Item -Path $tmpDirectory -ItemType file -ErrorAction SilentlyContinue
Test-Path $FullyQualifiedFile | Should Be $false
+18 -18
View File
@@ -1,38 +1,38 @@
Describe "Remove-Event" {
BeforeEach{
New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage"
BeforeEach {
New-Event -sourceidentifier PesterTimer -sender Windows.timer -messagedata "PesterTestMessage"
}
AfterEach {
Remove-Event -sourceidentifier PesterTimer -ErrorAction SilentlyContinue
}
AfterEach{
Remove-Event -sourceidentifier PesterTimer -ErrorAction SilentlyContinue
}
Context "Check Remove-Event can validly remove events" {
It "Should remove an event given a sourceidentifier" {
{ Remove-Event -sourceidentifier PesterTimer }
{ Remove-Event -sourceidentifier PesterTimer }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain PesterTimer }
}
}
It "Should remove an event given an event identifier" {
{ $events = Get-Event -sourceidentifier PesterTimer }
{ $events = $events.EventIdentifier }
{ Remove-Event -EventIdentifier $events }
{ $events = $events.EventIdentifier }
{ Remove-Event -EventIdentifier $events }
{ $events = Get-Event -ErrorAction SilentlyContinue}
{ $events.SourceIdentifier | Should Not Contain "PesterTimer" }
}
{ $events.SourceIdentifier | Should Not Contain "PesterTimer" }
}
It "Should be able to remove an event given a pipe from Get-Event" {
{ Get-Event -sourceidentifier PesterTimer | Remove-Event }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain "PesterTimer" }
It "Should be able to remove an event given a pipe from Get-Event" {
{ Get-Event -sourceidentifier PesterTimer | Remove-Event }
{ Get-Event -ErrorAction SilentlyContinue | Should Not Contain "PesterTimer" }
}
}
It "Should NOT remove an event given the whatif flag" {
It "Should NOT remove an event given the whatif flag" {
{ Remove-Event -sourceidentifier PesterTimer -whatif }
{ $events = Get-Event }
{ $events.SourceIdentifier | Should Contain "PesterTimer" }
}
}
}
}
@@ -73,4 +73,4 @@ Get-Date
#Clean up after ourselves
Remove-Item $testScript
}
}
+1 -1
View File
@@ -52,7 +52,7 @@
$output = $in | Format-List -Property Description | Out-String
# This will cause errors running these tests in windows
# This will cause errors running these tests in Windows
$output | Should Be "${nl}${nl}Description : test description${nl}${nl}${nl}${nl}"
}
+1 -1
View File
@@ -21,7 +21,7 @@
Split-Path ${qualifier}usr/bin -Qualifier | Should Be "$qualifier"
}
It "Should error when using the qualifier switch for a windows path while on a nonwindows machine" {
It "Should error when using the qualifier switch for a Windows path while on a non-Windows machine" {
# ErrorAction SilentlyContinue merely suppresses the error from the console.
# Throwing exceptions still seen by Pester.
+122 -122
View File
@@ -1,122 +1,122 @@
Describe "Test-Path" {
BeforeAll {
$testdirectory = $TestDrive
$testfilename = New-Item -path $testdirectory -Name testfile.txt -ItemType file -Value 1 -force
# populate with additional files
New-Item -Path $testdirectory -Name datestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name gatestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name usr -value 1 -ItemType directory | Out-Null
$nonExistantDir = Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin
$nonExistantPath = Join-Path -Path (Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin) -ChildPath error
}
It "Should be called on an existing path without error" {
{ Test-Path $testdirectory } | Should Not Throw
{ Test-Path -Path $testdirectory } | Should Not Throw
{ Test-Path -LiteralPath $testdirectory } | Should Not Throw
}
It "Should allow piping objects to it" {
{ $testdirectory | Test-Path } | Should Not Throw
$testdirectory | Test-Path | Should Be $true
$nonExistantDir | Test-Path | Should Be $false
}
It "Should be called on a nonexistant path without error" {
{ Test-Path -Path $nonExistantPath } | Should Not Throw
}
It "Should return false for a nonexistant path" {
Test-Path -Path $nonExistantPath | Should Be $false
}
It "Should return true for an existing path" {
{ Test-Path -Path $testdirectory } | Should Be $true
}
It "Should be able to accept a regular expression" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") } | Should Not Throw
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") } | Should Not Throw
}
It "Should be able to return the correct result when a regular expression is used" {
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "aoeu*") | Should Be $false
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[A-Z]") | Should Be $false
}
It "Should return false when the Leaf pathtype is used on a directory" {
Test-Path -Path $testdirectory -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on an existing endpoint" {
Test-Path -Path $testfilename -PathType Leaf | Should Be $true
}
It "Should return false when the Leaf pathtype is used on a nonexistant file" {
Test-Path -Path "aoeu" -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" {
Test-Path -Path $testfilename -Type Leaf | Should Be $true
}
It "Should be able to search multiple regular expressions using the include switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Include t* } | Should Be $true
}
It "Should be able to exclude a regular expression using the exclude switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Exclude v* } | Should Be $true
}
It "Should be able to exclude multiple regular expressions using the exclude switch" {
# tests whether there's any files in the usr directory that don't start with 'd' or 'g'
{ Test-Path -Path $testfilename -Exclude d*, g* } | Should Be $true
}
It "Should return true if the syntax of the path is correct when using the IsValid switch" {
{ Test-Path -Path $nonExistantPath -IsValid } | Should Be $true
}
It "Should return false if the syntax of the path is incorrect when using the IsValid switch" {
$badPath = " :;!@#$%^&*(){}?+|_-"
Test-Path -Path $badPath -IsValid | Should Be $false
}
It "Should return true on paths containing spaces when the path is surrounded in quotes" {
Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true
}
It "Should throw on paths containing spaces when the path is not surrounded in quotes" {
{ Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw
}
It "Should return true if a directory leads or trails with a space when surrounded by quotes" {
Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true
}
It "Should return true on a valid path when the LiteralPath switch is used" {
Test-Path -LiteralPath $testfilename | Should Be $true
}
It "Should return false if regular expressions are used with the LiteralPath switch" {
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" {
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return true if used on components other than filesystem objects" {
Test-Path Alias:\gci | Should Be $true
Test-Path Env:\PATH | Should Be $true
}
}
Describe "Test-Path" {
BeforeAll {
$testdirectory = $TestDrive
$testfilename = New-Item -path $testdirectory -Name testfile.txt -ItemType file -Value 1 -force
# populate with additional files
New-Item -Path $testdirectory -Name datestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name gatestfile -value 1 -ItemType file | Out-Null
New-Item -Path $testdirectory -Name usr -value 1 -ItemType directory | Out-Null
$nonExistantDir = Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin
$nonExistantPath = Join-Path -Path (Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin) -ChildPath error
}
It "Should be called on an existing path without error" {
{ Test-Path $testdirectory } | Should Not Throw
{ Test-Path -Path $testdirectory } | Should Not Throw
{ Test-Path -LiteralPath $testdirectory } | Should Not Throw
}
It "Should allow piping objects to it" {
{ $testdirectory | Test-Path } | Should Not Throw
$testdirectory | Test-Path | Should Be $true
$nonExistantDir | Test-Path | Should Be $false
}
It "Should be called on a nonexistant path without error" {
{ Test-Path -Path $nonExistantPath } | Should Not Throw
}
It "Should return false for a nonexistant path" {
Test-Path -Path $nonExistantPath | Should Be $false
}
It "Should return true for an existing path" {
{ Test-Path -Path $testdirectory } | Should Be $true
}
It "Should be able to accept a regular expression" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") } | Should Not Throw
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") } | Should Not Throw
}
It "Should be able to return the correct result when a regular expression is used" {
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]*") | Should Be $true
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "aoeu*") | Should Be $false
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[A-Z]") | Should Be $false
}
It "Should return false when the Leaf pathtype is used on a directory" {
Test-Path -Path $testdirectory -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on an existing endpoint" {
Test-Path -Path $testfilename -PathType Leaf | Should Be $true
}
It "Should return false when the Leaf pathtype is used on a nonexistant file" {
Test-Path -Path "aoeu" -PathType Leaf | Should Be $false
}
It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" {
Test-Path -Path $testfilename -Type Leaf | Should Be $true
}
It "Should be able to search multiple regular expressions using the include switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Include t* } | Should Be $true
}
It "Should be able to exclude a regular expression using the exclude switch" {
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Exclude v* } | Should Be $true
}
It "Should be able to exclude multiple regular expressions using the exclude switch" {
# tests whether there's any files in the usr directory that don't start with 'd' or 'g'
{ Test-Path -Path $testfilename -Exclude d*, g* } | Should Be $true
}
It "Should return true if the syntax of the path is correct when using the IsValid switch" {
{ Test-Path -Path $nonExistantPath -IsValid } | Should Be $true
}
It "Should return false if the syntax of the path is incorrect when using the IsValid switch" {
$badPath = " :;!@#$%^&*(){}?+|_-"
Test-Path -Path $badPath -IsValid | Should Be $false
}
It "Should return true on paths containing spaces when the path is surrounded in quotes" {
Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true
}
It "Should throw on paths containing spaces when the path is not surrounded in quotes" {
{ Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw
}
It "Should return true if a directory leads or trails with a space when surrounded by quotes" {
Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true
}
It "Should return true on a valid path when the LiteralPath switch is used" {
Test-Path -LiteralPath $testfilename | Should Be $true
}
It "Should return false if regular expressions are used with the LiteralPath switch" {
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" {
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
}
It "Should return true if used on components other than filesystem objects" {
Test-Path Alias:\gci | Should Be $true
Test-Path Env:\PATH | Should Be $true
}
}