Skip to content

Commit a5172f4

Browse files
authored
Merge pull request #7 from PlagueHO/Issue-6
Enabled PSSA rule violations to fail build - Fixes #6
2 parents 063923f + d0cf557 commit a5172f4

9 files changed

+195
-188
lines changed

.MetaTestOptIn.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
"Common Tests - Validate Markdown Files",
33
"Common Tests - Validate Example Files",
44
"Common Tests - Validate Module Files",
5-
"Common Tests - Validate Script Files"
5+
"Common Tests - Validate Script Files",
6+
"Common Tests - Required Script Analyzer Rules",
7+
"Common Tests - Flagged Script Analyzer Rules",
8+
"Common Tests - New Error-Level Script Analyzer Rules",
9+
"Common Tests - Custom Script Analyzer Rules"
610
]

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Enabled PSSA rule violations to fail build - Fixes [Issue #6](https://github.com/PlagueHO/FileContentDsc/issues/6).
6+
- Updated tests to meet Pester v4 standard.
7+
58
## 1.0.0.0
69

710
- DSR_ReplaceText:

Tests/Integration/DSR_IniSettingsFile.Integration.Tests.ps1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

44
Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1')
@@ -85,26 +85,26 @@ SettingThree=Value3
8585
-ConfigurationData $configData
8686

8787
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
88-
} | Should Not Throw
88+
} | Should -Not -Throw
8989
}
9090

9191
It 'Should be able to call Get-DscConfiguration without throwing' {
92-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
92+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
9393
}
9494

9595
It 'Should have set the resource and all the parameters should match' {
9696
$script:current = $script:currentDscConfig | Where-Object {
9797
$_.ConfigurationName -eq $script:configurationName
9898
}
99-
$current.Path | Should Be $script:testTextFile
100-
$current.Section | Should Be $script:testSection
101-
$current.Key | Should Be $script:testKey
102-
$current.Type | Should Be 'Text'
103-
$current.Text | Should Be $script:testText
99+
$current.Path | Should -Be $script:testTextFile
100+
$current.Section | Should -Be $script:testSection
101+
$current.Key | Should -Be $script:testKey
102+
$current.Type | Should -Be 'Text'
103+
$current.Text | Should -Be $script:testText
104104
}
105105

106106
It 'Should be convert the file content to match expected content' {
107-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedTextContent
107+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedTextContent
108108
}
109109

110110
AfterAll {
@@ -147,26 +147,26 @@ SettingThree=Value3
147147
-ConfigurationData $configData
148148

149149
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
150-
} | Should Not Throw
150+
} | Should -Not -Throw
151151
}
152152

153153
It 'Should be able to call Get-DscConfiguration without throwing' {
154-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
154+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
155155
}
156156

157157
It 'Should have set the resource and all the parameters should match' {
158158
$script:current = $script:currentDscConfig | Where-Object {
159159
$_.ConfigurationName -eq $script:configurationName
160160
}
161-
$current.Path | Should Be $script:testTextFile
162-
$current.Section | Should Be $script:testSection
163-
$current.Key | Should Be $script:testKey
164-
$current.Type | Should Be 'Text'
165-
$current.Text | Should Be $script:testSecret
161+
$current.Path | Should -Be $script:testTextFile
162+
$current.Section | Should -Be $script:testSection
163+
$current.Key | Should -Be $script:testKey
164+
$current.Type | Should -Be 'Text'
165+
$current.Text | Should -Be $script:testSecret
166166
}
167167

168168
It 'Should be convert the file content to match expected content' {
169-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedSecretContent
169+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedSecretContent
170170
}
171171

172172
AfterAll {

Tests/Integration/DSR_KeyValuePairFile.Integration.Tests.ps1

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

44
Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1')
@@ -87,26 +87,26 @@ Setting3.Test=Value4
8787
-ConfigurationData $configData
8888

8989
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
90-
} | Should Not Throw
90+
} | Should -Not -Throw
9191
}
9292

9393
It 'Should be able to call Get-DscConfiguration without throwing' {
94-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
94+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
9595
}
9696

9797
It 'Should have set the resource and all the parameters should match' {
9898
$script:current = $script:currentDscConfig | Where-Object {
9999
$_.ConfigurationName -eq $script:configurationName
100100
}
101-
$current.Path | Should Be $script:testTextFile
102-
$current.Name | Should Be $script:testName
103-
$current.Ensure | Should Be 'Present'
104-
$current.Type | Should Be 'Text'
105-
$current.Text | Should Be "$($script:testText),$($script:testText),$($script:testText)"
101+
$current.Path | Should -Be $script:testTextFile
102+
$current.Name | Should -Be $script:testName
103+
$current.Ensure | Should -Be 'Present'
104+
$current.Type | Should -Be 'Text'
105+
$current.Text | Should -Be "$($script:testText),$($script:testText),$($script:testText)"
106106
}
107107

108108
It 'Should be convert the file content to match expected content' {
109-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedTextContent
109+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedTextContent
110110
}
111111

112112
AfterAll {
@@ -149,26 +149,26 @@ Setting3.Test=Value4
149149
-ConfigurationData $configData
150150

151151
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
152-
} | Should Not Throw
152+
} | Should -Not -Throw
153153
}
154154

155155
It 'Should be able to call Get-DscConfiguration without throwing' {
156-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
156+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
157157
}
158158

159159
It 'Should have set the resource and all the parameters should match' {
160160
$script:current = $script:currentDscConfig | Where-Object {
161161
$_.ConfigurationName -eq $script:configurationName
162162
}
163-
$current.Path | Should Be $script:testTextFile
164-
$current.Name | Should Be $script:testName
165-
$current.Ensure | Should Be 'Present'
166-
$current.Type | Should Be 'Text'
167-
$current.Text | Should Be "$($script:testSecret),$($script:testSecret),$($script:testSecret)"
163+
$current.Path | Should -Be $script:testTextFile
164+
$current.Name | Should -Be $script:testName
165+
$current.Ensure | Should -Be 'Present'
166+
$current.Type | Should -Be 'Text'
167+
$current.Text | Should -Be "$($script:testSecret),$($script:testSecret),$($script:testSecret)"
168168
}
169169

170170
It 'Should be convert the file content to match expected content' {
171-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedSecretContent
171+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedSecretContent
172172
}
173173

174174
AfterAll {
@@ -208,26 +208,26 @@ Setting3.Test=Value4
208208
-ConfigurationData $configData
209209

210210
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
211-
} | Should Not Throw
211+
} | Should -Not -Throw
212212
}
213213

214214
It 'Should be able to call Get-DscConfiguration without throwing' {
215-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
215+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
216216
}
217217

218218
It 'Should have set the resource and all the parameters should match' {
219219
$script:current = $script:currentDscConfig | Where-Object {
220220
$_.ConfigurationName -eq $script:configurationName
221221
}
222-
$current.Path | Should Be $script:testTextFile
223-
$current.Name | Should Be $script:testName
224-
$current.Ensure | Should Be 'Absent'
225-
$current.Type | Should Be 'Text'
226-
$current.Text | Should BeNullOrEmpty
222+
$current.Path | Should -Be $script:testTextFile
223+
$current.Name | Should -Be $script:testName
224+
$current.Ensure | Should -Be 'Absent'
225+
$current.Type | Should -Be 'Text'
226+
$current.Text | Should -BeNullOrEmpty
227227
}
228228

229229
It 'Should be convert the file content to match expected content' {
230-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedAbsentContent
230+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedAbsentContent
231231
}
232232

233233
AfterAll {

Tests/Integration/DSR_ReplaceText.Integration.Tests.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
22
param ()
33

44
Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1')
@@ -82,25 +82,25 @@ Setting3.Test=Value4
8282
-ConfigurationData $configData
8383

8484
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
85-
} | Should Not Throw
85+
} | Should -Not -Throw
8686
}
8787

8888
It 'Should be able to call Get-DscConfiguration without throwing' {
89-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
89+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
9090
}
9191

9292
It 'Should have set the resource and all the parameters should match' {
9393
$script:current = $script:currentDscConfig | Where-Object {
9494
$_.ConfigurationName -eq $script:configurationName
9595
}
96-
$current.Path | Should Be $script:testTextFile
97-
$current.Search | Should Be $script:testSearch
98-
$current.Type | Should Be 'Text'
99-
$current.Text | Should Be "$($script:testTextReplace),$($script:testTextReplace),$($script:testTextReplace)"
96+
$current.Path | Should -Be $script:testTextFile
97+
$current.Search | Should -Be $script:testSearch
98+
$current.Type | Should -Be 'Text'
99+
$current.Text | Should -Be "$($script:testTextReplace),$($script:testTextReplace),$($script:testTextReplace)"
100100
}
101101

102102
It 'Should be convert the file content to match expected content' {
103-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedTextContent
103+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedTextContent
104104
}
105105

106106
AfterAll {
@@ -142,25 +142,25 @@ Setting3.Test=Value4
142142
-ConfigurationData $configData
143143

144144
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force -Verbose
145-
} | Should Not Throw
145+
} | Should -Not -Throw
146146
}
147147

148148
It 'Should be able to call Get-DscConfiguration without throwing' {
149-
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
149+
{ $script:currentDscConfig = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -throw
150150
}
151151

152152
It 'Should have set the resource and all the parameters should match' {
153153
$script:current = $script:currentDscConfig | Where-Object {
154154
$_.ConfigurationName -eq $script:configurationName
155155
}
156-
$current.Path | Should Be $script:testTextFile
157-
$current.Search | Should Be $script:testSearch
158-
$current.Type | Should Be 'Text'
159-
$current.Text | Should Be "$($script:testSecretReplace),$($script:testSecretReplace),$($script:testSecretReplace)"
156+
$current.Path | Should -Be $script:testTextFile
157+
$current.Search | Should -Be $script:testSearch
158+
$current.Type | Should -Be 'Text'
159+
$current.Text | Should -Be "$($script:testSecretReplace),$($script:testSecretReplace),$($script:testSecretReplace)"
160160
}
161161

162162
It 'Should be convert the file content to match expected content' {
163-
Get-Content -Path $script:testTextFile -Raw | Should Be $script:testFileExpectedSecretContent
163+
Get-Content -Path $script:testTextFile -Raw | Should -Be $script:testFileExpectedSecretContent
164164
}
165165

166166
AfterAll {

0 commit comments

Comments
 (0)