Added Pester tests for Get-FileHash
This commit is contained in:
parent
90202d0f59
commit
37b4eccb5b
1 changed files with 50 additions and 0 deletions
50
src/pester-tests/Get-FileHash.Tests.ps1
Normal file
50
src/pester-tests/Get-FileHash.Tests.ps1
Normal file
|
@ -0,0 +1,50 @@
|
|||
Describe "Get-FileHash" {
|
||||
New-Variable testDocument -Value $PSScriptRoot/assets/testablescript.ps1 -Scope Global -Force
|
||||
# The MACTripleDES and RIPEMD160 algorithms are unsupported at the moment
|
||||
$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
|
||||
|
||||
# regular expression for the forward/backslashes for linux/windows compatability
|
||||
$result.Path | Should Match "assets[/|\\]testablescript.ps1"
|
||||
}
|
||||
}
|
||||
|
||||
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."
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue