Skip to content

Commit 446ab85

Browse files
committed
Add Tests for UseShouldProcessForStateChangingFunctions
1 parent 731f456 commit 446ab85

3 files changed

+47
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Get-Service
2+
{
3+
param ([string]$c)
4+
}
5+
6+
function Get-MyObject{
7+
[CmdletBinding(SupportsShouldProcess = $false)]
8+
param([string]$c, [int]$d)
9+
10+
}
11+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Import-Module PSScriptAnalyzer
2+
$violationMessage = "File AvoidConvertToSecureStringWithPlainText.ps1 uses ConvertTo-SecureString with plaintext. This will expose secure information. Encrypted standard strings should be used instead."
3+
$violationName = "PS.UseShouldProcessForStateChangingFunctions"
4+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
$violations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctions.ps1 | Where-Object {$_.RuleName -eq $violationName}
6+
$noViolations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctionsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
7+
8+
Describe "" {
9+
Context "When there are violations" {
10+
It "has 2 violations where ShouldProcess is not supported" {
11+
$violations.Count | Should Be 3
12+
}
13+
14+
It "has the correct description message" {
15+
$violations[0].Message | Should Match $violationMessage
16+
}
17+
}
18+
19+
Context "When there are no violations" {
20+
It "returns no violations" {
21+
$noViolations.Count | Should Be 0
22+
}
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function Get-Service
2+
{
3+
[CmdletBinding(SupportShouldSuppress= $false)]
4+
param ([string]$c)
5+
}
6+
7+
function Test-GetMyObject{
8+
9+
param([string]$c, [int]$d)
10+
11+
}
12+

0 commit comments

Comments
 (0)