Skip to content

Commit ed70887

Browse files
authored
Remove Get-RegistryPropertyValue function (#2076)
#### Pull Request (PR) description - SqlServerDsc.Common - Removed the function `Get-RegistryPropertyValue` in favor of the command with the same name in the module _DscResource.Common_. #### This Pull Request (PR) fixes the following issues None. #### Task list <!-- To aid community reviewers in reviewing and merging your PR, please take the time to run through the below checklist and make sure your PR has everything updated as required. Change to [x] for each task in the task list that applies to your PR. For those task that don't apply to you PR, leave those unchecked. --> - [x] Added an entry to the change log under the Unreleased section of the file CHANGELOG.md. Entry should say what was changed and how that affects users (if applicable), and reference the issue being resolved (if applicable). - [ ] Resource documentation updated in the resource's README.md. - [ ] Resource parameter descriptions updated in schema.mof. - [ ] Comment-based help updated, including parameter descriptions. - [ ] Localization strings updated. - [ ] Examples updated. - [x] Unit tests updated. See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines). - [ ] Integration tests updated (where possible). See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines). - [x] Code changes adheres to [DSC Community Style Guidelines](https://dsccommunity.org/styleguidelines). <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dsccommunity/SqlServerDsc/2076) <!-- Reviewable:end -->
1 parent 17a73d9 commit ed70887

File tree

4 files changed

+6
-110
lines changed

4 files changed

+6
-110
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Removed
9+
10+
- SqlServerDsc.Common
11+
- Removed the function `Get-RegistryPropertyValue` in favor of the command
12+
with the same name in the module _DscResource.Common_.
13+
814
### Added
915

1016
- Public commands:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
2323
FunctionsToExport = @(
24-
'Get-RegistryPropertyValue'
2524
'Format-Path'
2625
'Copy-ItemWithRobocopy'
2726
'Invoke-InstallationMediaCopy'

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,6 @@ Import-Module -Name $script:resourceHelperModulePath
44

55
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
66

7-
<#
8-
.SYNOPSIS
9-
Returns the value of the provided Name parameter at the registry
10-
location provided in the Path parameter.
11-
12-
.PARAMETER Path
13-
Specifies the path in the registry to the property name.
14-
15-
.PARAMETER PropertyName
16-
Specifies the the name of the property to return the value for.
17-
#>
18-
function Get-RegistryPropertyValue
19-
{
20-
[CmdletBinding()]
21-
[OutputType([System.String])]
22-
param
23-
(
24-
[Parameter(Mandatory = $true)]
25-
[System.String]
26-
$Path,
27-
28-
[Parameter(Mandatory = $true)]
29-
[System.String]
30-
$Name
31-
)
32-
33-
$getItemPropertyParameters = @{
34-
Path = $Path
35-
Name = $Name
36-
}
37-
38-
<#
39-
Using a try/catch block instead of 'SilentlyContinue' to be
40-
able to unit test a failing registry path.
41-
#>
42-
try
43-
{
44-
$getItemPropertyResult = (Get-ItemProperty @getItemPropertyParameters -ErrorAction 'Stop').$Name
45-
}
46-
catch
47-
{
48-
$getItemPropertyResult = $null
49-
}
50-
51-
return $getItemPropertyResult
52-
}
53-
547
<#
558
.SYNOPSIS
569
Returns the value of the provided in the Name parameter, at the registry

tests/Unit/SqlServerDsc.Common.Tests.ps1

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -83,68 +83,6 @@ AfterAll {
8383
Get-Module -Name 'CommonTestHelper' -All | Remove-Module -Force
8484
}
8585

86-
Describe 'SqlServerDsc.Common\Get-RegistryPropertyValue' -Tag 'GetRegistryPropertyValue' {
87-
BeforeAll {
88-
$mockWrongRegistryPath = 'HKLM:\SOFTWARE\AnyPath'
89-
$mockPropertyName = 'InstanceName'
90-
$mockPropertyValue = 'AnyValue'
91-
}
92-
93-
Context 'When there are no property in the registry' {
94-
BeforeAll {
95-
Mock -CommandName Get-ItemProperty -MockWith {
96-
return @{
97-
'UnknownProperty' = $mockPropertyValue
98-
}
99-
}
100-
}
101-
102-
It 'Should return $null' {
103-
$result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName
104-
$result | Should -BeNullOrEmpty
105-
106-
Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It -Module $script:subModuleName
107-
}
108-
}
109-
110-
Context 'When the call to Get-ItemProperty throws an error (i.e. when the path does not exist)' {
111-
BeforeAll {
112-
Mock -CommandName Get-ItemProperty -MockWith {
113-
throw 'mocked error'
114-
}
115-
}
116-
117-
It 'Should not throw an error, but return $null' {
118-
$result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName
119-
$result | Should -BeNullOrEmpty
120-
121-
Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It
122-
}
123-
}
124-
125-
Context 'When there are a property in the registry' {
126-
BeforeAll {
127-
$mockCorrectRegistryPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS'
128-
129-
Mock -CommandName Get-ItemProperty -MockWith {
130-
return @{
131-
$mockPropertyName = $mockPropertyValue
132-
}
133-
} -ParameterFilter {
134-
$Path -eq $mockCorrectRegistryPath `
135-
-and $Name -eq $mockPropertyName
136-
}
137-
}
138-
139-
It 'Should return the correct value' {
140-
$result = Get-RegistryPropertyValue -Path $mockCorrectRegistryPath -Name $mockPropertyName
141-
$result | Should -Be $mockPropertyValue
142-
143-
Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It
144-
}
145-
}
146-
}
147-
14886
Describe 'SqlServerDsc.Common\Format-Path' -Tag 'FormatPath' {
14987
BeforeAll {
15088
$mockCorrectPath = 'C:\Correct\Path'

0 commit comments

Comments
 (0)