Skip to content

Commit

Permalink
Fixes more TestRegistry parallel issues (#1224)
Browse files Browse the repository at this point in the history
Fixes more TestRegistry parallel issues

Fix #1216
  • Loading branch information
nohwnd authored Jan 21, 2019
1 parent 3e77d00 commit 600abd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
10 changes: 1 addition & 9 deletions Functions/Environment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,10 @@ InModuleScope -ModuleName Pester {

It 'return the corret temp registry for Windows' {

$expected = 'HKCU:\Software\Pester'
$expected = 'Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Pester'
$tempPath = Get-TempRegistry
$tempPath | Should -Be $expected
}

It 'should throw an error if TempRegistry fails' {
Mock New-TempRegistry {
throw [Exception] 'Error'
}

{ Get-TempRegistry } | Should -Throw 'Was not able to create a Pester Registry key for TestRegistry'
}
}
}
}
10 changes: 3 additions & 7 deletions Functions/Environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ function Get-TempDirectory {
}

function Get-TempRegistry {
$pesterTempRegistryRoot = 'HKCU:\Software\Pester'
if (Test-Path 'HKCU:\Software\Pester') {
$pesterTempRegistryRoot = 'Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Pester'
if (-not (Test-Path $pesterTempRegistryRoot)) {
try {
$null = New-TempRegistry
$null = New-Item -Path $pesterTempRegistryRoot -ErrorAction Stop
}
catch [Exception] {
throw (New-Object Exception -ArgumentList "Was not able to create a Pester Registry key for TestRegistry", ($_.Exception))
}
}
return $pesterTempRegistryRoot
}

function New-TempRegistry {
New-Item -Path 'HKCU:\Software\Pester' -Force
}
8 changes: 2 additions & 6 deletions Functions/TestRegistry.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
function New-TestRegistry {
param(
[Switch]
Expand Down Expand Up @@ -51,17 +50,14 @@ function New-TestRegistry {
}
}
}
else {
write-host "registry drive exists"
}

if ( $PassThru ) {
& $SafeCommands['Get-PSDrive'] -Name $DriveName
}
}

function Get-TestRegistryPath () {
"Microsoft.PowerShell.Core\Registry::" + (& $SafeCommands['Get-PSDrive'] -Name TestRegistry).Root
"Microsoft.PowerShell.Core\Registry::" + (& $SafeCommands['Get-PSDrive'] -Name TestRegistry -ErrorAction Stop).Root
}

function Clear-TestRegistry {
Expand Down Expand Up @@ -93,7 +89,7 @@ function New-RandomTempRegistry {
$Path = & $SafeCommands['Join-Path'] -Path $tempPath -ChildPath ([Guid]::NewGuid())
} until (-not (& $SafeCommands['Test-Path'] -Path $Path ))

& $SafeCommands['New-Item'] -Path $Path -Force
& $SafeCommands['New-Item'] -Path $Path
}

function Remove-TestRegistry {
Expand Down

0 comments on commit 600abd2

Please sign in to comment.