Skip to content

Commit 83c8385

Browse files
authored
SqlServerDsc: Remove Test-PendingRestart function (#2098)
- SqlServerDsc.Common - Removed the function `Test-PendingRestart` in favor of the commands with the same names in the module _DscResource.Common_.
1 parent 012ea6b commit 83c8385

File tree

8 files changed

+8
-63
lines changed

8 files changed

+8
-63
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Revert workaround in GitHub Actions workflows as new version of ModuleBuilder
1212
was released.
1313
- SqlServerDsc.Common
14-
- Removed the function `Get-RegistryPropertyValue` and `Format-Path` in
15-
favor of the commands with the same names in the module _DscResource.Common_.
14+
- Removed the function `Get-RegistryPropertyValue`, `Format-Path` and
15+
`Test-PendingRestart` in favor of the commands with the same names in
16+
the module _DscResource.Common_.
1617

1718
### Added
1819

source/DSCResources/DSC_SqlRSSetup/DSC_SqlRSSetup.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function Set-TargetResource
527527

528528
Write-Verbose -Message $script:localizedData.SuppressRestart
529529
}
530-
elseif (-not $SuppressRestart -and (Test-PendingRestart))
530+
elseif (-not $SuppressRestart -and (Test-PendingRestart -Check 'PendingFileRename'))
531531
{
532532
$global:DSCMachineStatus = 1
533533
}

source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ function Set-TargetResource
17071707
Write-Verbose -Message $setupExitMessageSuccessful
17081708
}
17091709

1710-
if ($ForceReboot -or (Test-PendingRestart))
1710+
if ($ForceReboot -or (Test-PendingRestart -Check 'PendingFileRename'))
17111711
{
17121712
if (-not ($SuppressReboot))
17131713
{

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
'Invoke-InstallationMediaCopy'
2727
'Connect-UncPath'
2828
'Disconnect-UncPath'
29-
'Test-PendingRestart'
3029
'Start-SqlSetupProcess'
3130
'Connect-SQL'
3231
'Connect-SQLAnalysis'

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,31 +249,6 @@ function Disconnect-UncPath
249249
Remove-SmbMapping -RemotePath $RemotePath -Force
250250
}
251251

252-
<#
253-
.SYNOPSIS
254-
Queries the registry and returns $true if there is a pending reboot.
255-
256-
.OUTPUTS
257-
Returns $true if there is a pending reboot, otherwise it returns $false.
258-
#>
259-
function Test-PendingRestart
260-
{
261-
[CmdletBinding()]
262-
[OutputType([System.Boolean])]
263-
param ()
264-
265-
$getRegistryPropertyValueParameters = @{
266-
Path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager'
267-
Name = 'PendingFileRenameOperations'
268-
}
269-
270-
<#
271-
If the key 'PendingFileRenameOperations' does not exist then if should
272-
return $false, otherwise it should return $true.
273-
#>
274-
return $null -ne (Get-RegistryPropertyValue @getRegistryPropertyValueParameters)
275-
}
276-
277252
<#
278253
.SYNOPSIS
279254
Starts the SQL setup process.

tests/Unit/DSC_SqlRSSetup.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' {
958958
Edition = 'Dev'
959959
}
960960

961-
Mock -CommandName Test-PendingRestart
961+
Mock -CommandName Test-PendingRestart -RemoveParameterType 'Check'
962962
Mock -CommandName Start-SqlSetupProcess -MockWith {
963963
Test-SetupArgument -Argument $ArgumentList -ExpectedArgument $mockStartSqlSetupProcess_ExpectedArgumentList
964964

@@ -996,7 +996,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' {
996996

997997
Mock -CommandName Test-PendingRestart -MockWith {
998998
return $true
999-
}
999+
} -RemoveParameterType 'Check'
10001000

10011001
Mock -CommandName Start-SqlSetupProcess -MockWith {
10021002
Test-SetupArgument -Argument $ArgumentList -ExpectedArgument $mockStartSqlSetupProcess_ExpectedArgumentList

tests/Unit/DSC_SqlSetup.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' {
22832283

22842284
Mock -CommandName Test-PendingRestart -MockWith {
22852285
return $false
2286-
}
2286+
} -RemoveParameterType 'Check'
22872287

22882288
InModuleScope -ScriptBlock {
22892289
# Mock PsDscRunAsCredential context.

tests/Unit/SqlServerDsc.Common.Tests.ps1

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -707,36 +707,6 @@ Describe 'SqlServerDsc.Common\Disconnect-UncPath' -Tag 'DisconnectUncPath' {
707707
}
708708
}
709709

710-
Describe 'SqlServerDsc.Common\Test-PendingRestart' -Tag 'TestPendingRestart' {
711-
Context 'When there is a pending reboot' {
712-
BeforeAll {
713-
Mock -CommandName Get-RegistryPropertyValue -MockWith {
714-
return 'AnyValue'
715-
}
716-
}
717-
718-
It 'Should return $true' {
719-
$testPendingRestartResult = Test-PendingRestart
720-
$testPendingRestartResult | Should -BeTrue
721-
722-
Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope It
723-
}
724-
}
725-
726-
Context 'When there are no pending reboot' {
727-
BeforeAll {
728-
Mock -CommandName Get-RegistryPropertyValue
729-
}
730-
731-
It 'Should return $true' {
732-
$testPendingRestartResult = Test-PendingRestart
733-
$testPendingRestartResult | Should -BeFalse
734-
735-
Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope It
736-
}
737-
}
738-
}
739-
740710
Describe 'SqlServerDsc.Common\Start-SqlSetupProcess' -Tag 'StartSqlSetupProcess' {
741711
BeforeAll {
742712
$mockPowerShellExecutable = if ($IsLinux -or $IsMacOS)

0 commit comments

Comments
 (0)