Skip to content

Commit bf9bcb3

Browse files
author
Kapil Borle
committed
Add tests for avoidalias rule whitelist
1 parent c54634f commit bf9bcb3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Tests/Rules/AvoidUsingAlias.tests.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ Describe "AvoidUsingAlias" {
3131
$noViolations.Count | Should Be 0
3232
}
3333
}
34+
35+
Context "Settings file provides whitelist" {
36+
$whiteListTestScriptDef = 'gci; cd; iwr'
37+
38+
It "honors the whitelist provided as hashtable" {
39+
$settings = @{
40+
'Rules' = @{
41+
'PSAvoidUsingCmdletAliases' = @{
42+
'Whitelist' = @('cd')
43+
}
44+
}
45+
}
46+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $whiteListTestScriptDef -Settings $settings -IncludeRule $violationName
47+
$violations.Count | Should Be 2
48+
}
49+
50+
It "honors the whitelist provided through settings file" {
51+
# even though join-path returns string, if we do not use tostring, then invoke-scriptanalyzer cannot cast it to string type
52+
$settingsFilePath = (Join-Path $directory (Join-Path 'TestSettings' 'AvoidAliasSettings.psd1')).ToString()
53+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $whiteListTestScriptDef -Settings $settingsFilePath -IncludeRule $violationName
54+
$violations.Count | Should be 2
55+
}
56+
}
3457
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
'Rules' = @{
3+
'PSAvoidUsingCmdletAliases' = @{
4+
'Whitelist' = @('cd')
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)