Skip to content

Commit 51fe7f3

Browse files
authored
Merge pull request #36 from PlagueHO/dev
Release 1.3.0.0
2 parents 2720866 + 8a22397 commit 51fe7f3

21 files changed

+2251
-1129
lines changed

.MetaTestOptIn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"Common Tests - Custom Script Analyzer Rules",
1010
"Common Tests - Validate Example Files To Be Published",
1111
"Common Tests - Validate Markdown Links",
12-
"Common Tests - Relative Path Length"
12+
"Common Tests - Relative Path Length",
13+
"Common Tests - Validate Localization"
1314
]

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Versions
22

3+
## 1.3.0.0
4+
5+
- Opted into Common Tests 'Common Tests - Validate Localization' -
6+
fixes [Issue #31](https://github.com/PlagueHO/FileContentDsc/issues/32).
7+
- Combined all `FileContent.ResourceHelper` module functions into
8+
`FileContent.Common` module - fixes [Issue #32](https://github.com/PlagueHO/FileContentDsc/issues/32).
9+
- Renamed all localization strings so that they are detected by
10+
'Common Tests - Validate Localization'.
11+
- Correct style violations in unit tests:
12+
- Adding `Get`, `Set` and `Test` tags to appropriate `describe` blocks.
13+
- Removing uneccesary `#region` blocks.
14+
- Conversion of double quotes to single quotes where possible.
15+
- Replace variables with string litterals in `describe` block description.
16+
- KeyValuePairFile:
17+
- Improve unit tests to simplify and cover additional test cases.
18+
- Fix error occuring when file is empty or does not exist - fixes [Issue #34](https://github.com/PlagueHO/FileContentDsc/issues/34).
19+
320
## 1.2.0.0
421

522
- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #25](https://github.com/PlagueHO/FileContentDsc/issues/25).

DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
1-
# Suppressed as per PSSA Rule Severity guidelines for unit/integration tests:
2-
# https://github.com/PowerShell/DscResources/blob/master/PSSARuleSeverities.md
3-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
4-
param ()
5-
61
Set-StrictMode -Version 'Latest'
72

83
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
94

10-
# Import the Storage Common Modules
5+
# Import the Networking Common Modules
116
Import-Module -Name (Join-Path -Path $modulePath `
127
-ChildPath (Join-Path -Path 'FileContentDsc.Common' `
138
-ChildPath 'FileContentDsc.Common.psm1'))
149

15-
# Import the Storage Resource Helper Module
16-
Import-Module -Name (Join-Path -Path $modulePath `
17-
-ChildPath (Join-Path -Path 'FileContentDsc.ResourceHelper' `
18-
-ChildPath 'FileContentDsc.ResourceHelper.psm1'))
19-
2010
# Import Localization Strings
21-
$localizedData = Get-LocalizedData `
22-
-ResourceName 'DSR_IniSettingsFile' `
23-
-ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)
11+
$script:localizedData = Get-LocalizedData -ResourceName 'DSR_IniSettingsFile'
2412

2513
<#
2614
.SYNOPSIS
@@ -43,23 +31,23 @@ function Get-TargetResource
4331
(
4432
[Parameter(Mandatory = $true)]
4533
[ValidateNotNullOrEmpty()]
46-
[String]
34+
[System.String]
4735
$Path,
4836

4937
[Parameter(Mandatory = $true)]
5038
[ValidateNotNullOrEmpty()]
51-
[String]
39+
[System.String]
5240
$Section,
5341

5442
[Parameter(Mandatory = $true)]
5543
[ValidateNotNullOrEmpty()]
56-
[String]
44+
[System.String]
5745
$Key
5846
)
5947

6048
Assert-ParametersValid @PSBoundParameters
6149

62-
Write-Verbose -Message ($localizedData.GetIniSettingMessage -f `
50+
Write-Verbose -Message ($script:localizedData.GetIniSettingMessage -f `
6351
$Path, $Section, $Key)
6452

6553
$text = Get-IniSettingFileValue @PSBoundParameters
@@ -99,33 +87,31 @@ function Get-TargetResource
9987
#>
10088
function Set-TargetResource
10189
{
102-
# Should process is called in a helper functions but not directly in Set-TargetResource
103-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
104-
[CmdletBinding(SupportsShouldProcess = $true)]
90+
[CmdletBinding()]
10591
param
10692
(
10793
[Parameter(Mandatory = $true)]
10894
[ValidateNotNullOrEmpty()]
109-
[String]
95+
[System.String]
11096
$Path,
11197

11298
[Parameter(Mandatory = $true)]
11399
[ValidateNotNullOrEmpty()]
114-
[String]
100+
[System.String]
115101
$Section,
116102

117103
[Parameter(Mandatory = $true)]
118104
[ValidateNotNullOrEmpty()]
119-
[String]
105+
[System.String]
120106
$Key,
121107

122108
[Parameter()]
123109
[ValidateSet('Text', 'Secret')]
124-
[String]
110+
[System.String]
125111
$Type = 'Text',
126112

127113
[Parameter()]
128-
[String]
114+
[System.String]
129115
$Text,
130116

131117
[Parameter()]
@@ -143,15 +129,15 @@ function Set-TargetResource
143129

144130
if ($Type -eq 'Secret')
145131
{
146-
Write-Verbose -Message ($localizedData.SetIniSettingSecretMessage -f `
132+
Write-Verbose -Message ($script:localizedData.SetIniSettingSecretMessage -f `
147133
$Path, $Section, $Key)
148134

149135
$Text = $Secret.GetNetworkCredential().Password
150136
$null = $PSBoundParameters.Remove('Secret')
151137
}
152138
else
153139
{
154-
Write-Verbose -Message ($localizedData.SetIniSettingTextMessage -f `
140+
Write-Verbose -Message ($script:localizedData.SetIniSettingTextMessage -f `
155141
$Path, $Section, $Key, $Text)
156142
} # if
157143

@@ -189,32 +175,32 @@ function Set-TargetResource
189175
#>
190176
function Test-TargetResource
191177
{
192-
[OutputType([Boolean])]
178+
[OutputType([System.Boolean])]
193179
[CmdletBinding()]
194180
param
195181
(
196182
[Parameter(Mandatory = $true)]
197183
[ValidateNotNullOrEmpty()]
198-
[String]
184+
[System.String]
199185
$Path,
200186

201187
[Parameter(Mandatory = $true)]
202188
[ValidateNotNullOrEmpty()]
203-
[String]
189+
[System.String]
204190
$Section,
205191

206192
[Parameter(Mandatory = $true)]
207193
[ValidateNotNullOrEmpty()]
208-
[String]
194+
[System.String]
209195
$Key,
210196

211197
[Parameter()]
212198
[ValidateSet('Text', 'Secret')]
213-
[String]
199+
[System.String]
214200
$Type = 'Text',
215201

216202
[Parameter()]
217-
[String]
203+
[System.String]
218204
$Text,
219205

220206
[Parameter()]
@@ -243,14 +229,14 @@ function Test-TargetResource
243229

244230
if ((Get-IniSettingFileValue @PSBoundParameters) -eq $Text)
245231
{
246-
Write-Verbose -Message ($localizedData.IniSettingMatchesMessage -f `
232+
Write-Verbose -Message ($script:localizedData.IniSettingMatchesMessage -f `
247233
$Path, $Section, $Key)
248234

249235
return $true
250236
}
251237
else
252238
{
253-
Write-Verbose -Message ($localizedData.IniSettingMismatchMessage -f `
239+
Write-Verbose -Message ($script:localizedData.IniSettingMismatchMessage -f `
254240
$Path, $Section, $Key)
255241

256242
return $false
@@ -289,26 +275,26 @@ function Assert-ParametersValid
289275
(
290276
[Parameter(Mandatory = $true)]
291277
[ValidateNotNullOrEmpty()]
292-
[String]
278+
[System.String]
293279
$Path,
294280

295281
[Parameter(Mandatory = $true)]
296282
[ValidateNotNullOrEmpty()]
297-
[String]
283+
[System.String]
298284
$Section,
299285

300286
[Parameter(Mandatory = $true)]
301287
[ValidateNotNullOrEmpty()]
302-
[String]
288+
[System.String]
303289
$Key,
304290

305291
[Parameter()]
306292
[ValidateSet('Text', 'Secret')]
307-
[String]
293+
[System.String]
308294
$Type = 'Text',
309295

310296
[Parameter()]
311-
[String]
297+
[System.String]
312298
$Text,
313299

314300
[Parameter()]
@@ -319,10 +305,11 @@ function Assert-ParametersValid
319305

320306
# Does the file's parent path exist?
321307
$parentPath = Split-Path -Path $Path -Parent
308+
322309
if (-not (Test-Path -Path $parentPath))
323310
{
324311
New-InvalidArgumentException `
325-
-Message ($localizedData.FileParentNotFoundError -f $parentPath) `
312+
-Message ($script:localizedData.FileParentNotFoundError -f $parentPath) `
326313
-ArgumentName 'Path'
327314
} # if
328315
}

0 commit comments

Comments
 (0)