Add test coverage for Registry (#4354)

* Add test coverage for Registry (#4148)

* Add coverage for Get-Item, Get-ChildItem, Set-Item, and Clear-Item

* Add test for accessing inaccessible path, per code review.
This commit is contained in:
jeffbi
2017-08-02 09:53:31 -07:00
committed by Aditya Patwardhan
parent 8f9aed806e
commit 19fcd43b85
@@ -13,6 +13,9 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
$testKey2 = "TestKey2"
$testPropertyName = "TestEntry"
$testPropertyValue = 1
$defaultPropertyName = "(Default)"
$defaultPropertyValue = "something"
$otherPropertyValue = "other"
}
}
@@ -44,6 +47,34 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
}
Context "Validate basic registry provider Cmdlets" {
It "Verify Test-Path" {
Test-Path -IsValid Registry::HKCU/Software | Should Be $true
Test-Path -IsValid Registry::foo/Softare | Should Be $false
}
It "Verify Get-Item" {
$item = Get-Item $testKey
$item.PSChildName | Should BeExactly $testKey
}
It "Verify Get-Item on inaccessible path" {
{ Get-Item HKLM:\SAM\SAM -ErrorAction Stop } | ShouldBeErrorId "System.Security.SecurityException,Microsoft.PowerShell.Commands.GetItemCommand"
}
It "Verify Get-ChildItem" {
$items = Get-ChildItem
$items.Count | Should BeExactly 2
$Items.PSChildName -contains $testKey | Should Be $true
$Items.PSChildName -contains $testKey2 | Should Be $true
}
It "Verify Get-ChildItem can get subkey names" {
$items = Get-ChildItem -Name
$items.Count | Should BeExactly 2
$items -contains $testKey | Should Be $true
$items -contains $testKey2 | Should Be $true
}
It "Verify New-Item" {
$newKey = New-Item -Path "NewItemTest"
Test-Path "NewItemTest" | Should Be $true
@@ -87,6 +118,19 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
$property."$testPropertyName" | Should Be 2
}
It "Verify Set-Item" {
Set-Item -Path $testKey -Value $defaultPropertyValue
$property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName
$property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue
}
It "Verify Set-Item with -WhatIf" {
Set-Item -Path $testKey -Value $defaultPropertyValue
Set-Item -Path $testKey -Value $otherPropertyValue -WhatIf
$property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName
$property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue
}
It "Verify Get-ItemPropertyValue" {
$propertyValue = Get-ItemPropertyValue -Path $testKey -Name $testPropertyName
$propertyValue | Should Be $testPropertyValue
@@ -125,6 +169,22 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
$property."$testPropertyName" | Should Be 0
}
It "Verify Clear-Item" {
Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue
Set-Item -Path $testKey -Value $defaultPropertyValue
Clear-Item -Path $testKey
$key = Get-Item -Path $testKey
$key.Property.Length | Should BeExactly 0
}
It "Verify Clear-Item with -WhatIf" {
Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue
Set-Item -Path $testKey -Value $defaultPropertyValue
Clear-Item -Path $testKey -WhatIf
$key = Get-Item -Path $testKey
$key.Property.Length | Should BeExactly 2
}
It "Verify Remove-ItemProperty" {
Remove-ItemProperty -Path $testKey -Name $testPropertyName
$properties = @(Get-ItemProperty -Path $testKey)