Skip to content

Commit

Permalink
xArchive: Remove Invoke-NewPSDrive - Fixes #698 (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO authored Sep 21, 2020
1 parent 2249995 commit 308d6b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
by changing `CopyDirectories` to `CopyPaths` - Fixes [Issue #687](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/687).
- Pin `Pester` module to 4.10.1 because Pester 5.0 is missing code
coverage - Fixes [Issue #688](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/688).
- xArchive
- Removed `Invoke-NewPSDrive` function because it is no longer needed as
Pester issue has been resolved - Fixes [Issue #698](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/698).

### Changed

Expand Down
26 changes: 1 addition & 25 deletions source/DSCResources/DSC_xArchive/DSC_xArchive.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -489,30 +489,6 @@ function New-Guid
return [System.Guid]::NewGuid()
}

<#
.SYNOPSIS
Invokes the cmdlet New-PSDrive with the specified parameters.
This is a wrapper function for unit testing due to a bug in Pester.
Issue has been filed here: https://github.com/pester/Pester/issues/728
.PARAMETER Parameters
A hashtable of parameters to splat to New-PSDrive.
#>
function Invoke-NewPSDrive
{
[OutputType([System.Management.Automation.PSDriveInfo])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Collections.Hashtable]
$Parameters
)

return New-PSDrive @Parameters
}

<#
.SYNOPSIS
Mounts a PSDrive to access the specified path with the permissions granted by the specified
Expand Down Expand Up @@ -582,7 +558,7 @@ function Mount-PSDriveWithCredential
try
{
Write-Verbose -Message ($script:localizedData.CreatingPSDrive -f $pathToPSDriveRoot, $Credential.UserName)
$newPSDrive = Invoke-NewPSDrive -Parameters $newPSDriveParameters
$newPSDrive = New-PSDrive @newPSDriveParameters
}
catch
{
Expand Down
30 changes: 15 additions & 15 deletions tests/Unit/DSC_xArchive.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ try
Describe 'xArchive\Mount-PSDriveWithCredential' {
Mock -CommandName 'Test-Path' -MockWith { return $true }
Mock -CommandName 'New-Guid' -MockWith { return $script:testGuid }
Mock -CommandName 'Invoke-NewPSDrive' -MockWith { throw 'Test error from New-PSDrive' }
Mock -CommandName 'New-PSDrive' -MockWith { throw 'Test error from New-PSDrive' }

Context 'When specified path is already accessible' {
$mountPSDriveWithCredentialParameters = @{
Expand All @@ -1601,7 +1601,7 @@ try
}

It 'Should not attempt to create a new PSDrive' {
Assert-MockCalled -CommandName 'Invoke-NewPSDrive' -Exactly 0 -Scope 'Context'
Assert-MockCalled -CommandName 'New-PSDrive' -Exactly 0 -Scope 'Context'
}

$mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters
Expand All @@ -1627,7 +1627,7 @@ try
}

$expectedPSDrive = New-MockObject -Type 'System.Management.Automation.PSDriveInfo'
Mock -CommandName 'Invoke-NewPSDrive' -MockWith { return $expectedPSDrive }
Mock -CommandName 'New-PSDrive' -MockWith { return $expectedPSDrive }

Context 'When specified path is not accessible, path contains a backslash but does not end with a backslash, and new PSDrive creation succeeds' {
$mountPSDriveWithCredentialParameters = @{
Expand Down Expand Up @@ -1656,16 +1656,16 @@ try

It 'Should create a new PSDrive' {
$newPSDriveParameterFilter = {
$nameParameterCorrect = $Parameters.Name -eq $script:testGuid
$psProviderParameterCorrect = $Parameters.PSProvider -eq 'FileSystem'
$rootParameterCorrect = $Parameters.Root -eq $expectedPSDrivePath
$scopeParameterCorrect = $Parameters.Scope -eq 'Script'
$credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mountPSDriveWithCredentialParameters.Credential -DifferenceObject $Parameters.Credential)
$nameParameterCorrect = $Name -eq $script:testGuid
$psProviderParameterCorrect = $PSProvider -eq 'FileSystem'
$rootParameterCorrect = $Root -eq $expectedPSDrivePath
$scopeParameterCorrect = $Scope -eq 'Script'
$credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mountPSDriveWithCredentialParameters.Credential -DifferenceObject $Credential)

return $nameParameterCorrect -and $psProviderParameterCorrect -and $rootParameterCorrect -and $scopeParameterCorrect -and $credentialParameterCorrect
}

Assert-MockCalled -CommandName 'Invoke-NewPSDrive' -ParameterFilter $newPSDriveParameterFilter -Exactly 1 -Scope 'Context'
Assert-MockCalled -CommandName 'New-PSDrive' -ParameterFilter $newPSDriveParameterFilter -Exactly 1 -Scope 'Context'
}

$mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters
Expand Down Expand Up @@ -1700,16 +1700,16 @@ try

It 'Should create a new PSDrive' {
$newPSDriveParameterFilter = {
$nameParameterCorrect = $Parameters.Name -eq $script:testGuid
$psProviderParameterCorrect = $Parameters.PSProvider -eq 'FileSystem'
$rootParameterCorrect = $Parameters.Root -eq $mountPSDriveWithCredentialParameters.Path
$scopeParameterCorrect = $Parameters.Scope -eq 'Script'
$credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mountPSDriveWithCredentialParameters.Credential -DifferenceObject $Parameters.Credential)
$nameParameterCorrect = $Name -eq $script:testGuid
$psProviderParameterCorrect = $PSProvider -eq 'FileSystem'
$rootParameterCorrect = $Root -eq $mountPSDriveWithCredentialParameters.Path
$scopeParameterCorrect = $Scope -eq 'Script'
$credentialParameterCorrect = $null -eq (Compare-Object -ReferenceObject $mountPSDriveWithCredentialParameters.Credential -DifferenceObject $Credential)

return $nameParameterCorrect -and $psProviderParameterCorrect -and $rootParameterCorrect -and $scopeParameterCorrect -and $credentialParameterCorrect
}

Assert-MockCalled -CommandName 'Invoke-NewPSDrive' -ParameterFilter $newPSDriveParameterFilter -Exactly 1 -Scope 'Context'
Assert-MockCalled -CommandName 'New-PSDrive' -ParameterFilter $newPSDriveParameterFilter -Exactly 1 -Scope 'Context'
}

$mountPSDriveWithCredentialResult = Mount-PSDriveWithCredential @mountPSDriveWithCredentialParameters
Expand Down

0 comments on commit 308d6b8

Please sign in to comment.