File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ Import-Module - Verbose PSScriptAnalyzer
2
+
3
+ $currentPath = Split-Path - Parent $MyInvocation.MyCommand.Path
4
+ $ruleName = " PSDSCDscExamplesPresent"
5
+
6
+ Describe " DscExamplesPresent rule in class based resource" {
7
+
8
+ $examplesPath = " $currentPath \DSCResources\MyDscResource\Examples"
9
+ $classResourcePath = " $currentPath \DSCResources\MyDscResource\MyDscResource.psm1"
10
+
11
+ Context " When examples absent" {
12
+
13
+ $violations = Invoke-ScriptAnalyzer - ErrorAction SilentlyContinue $classResourcePath | Where-Object {$_.RuleName -eq $ruleName }
14
+ $violationMessage = " No examples found for resource 'FileResource'"
15
+
16
+ It " has 1 missing examples violation" {
17
+ $violations.Count | Should Be 1
18
+ }
19
+
20
+ It " has the correct description message" {
21
+ $violations [0 ].Message | Should Match $violationMessage
22
+ }
23
+ }
24
+
25
+ Context " When examples present" {
26
+ New-Item - Path $examplesPath - ItemType Directory
27
+ New-Item - Path " $examplesPath \FileResource_Example.psm1" - ItemType File
28
+
29
+ $noViolations = Invoke-ScriptAnalyzer - ErrorAction SilentlyContinue $classResourcePath | Where-Object {$_.RuleName -eq $ruleName }
30
+
31
+ It " returns no violations" {
32
+ $noViolations.Count | Should Be 0
33
+ }
34
+
35
+ Remove-Item - Path $examplesPath - Recurse - Force
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments