|
1 | 1 | Import-Module PSScriptAnalyzer
|
2 | 2 | $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
|
3 | 3 | $ruleName = 'PSDSCUseIdenticalMandatoryParametersForDSC'
|
4 |
| -$resourceFilepath = [System.IO.Path]::Combine( |
5 |
| - $directory, |
6 |
| - 'DSCResourceModule', |
7 |
| - 'DSCResources', |
| 4 | +$resourceBasepath = "$directory\DSCResourceModule\DSCResources" |
| 5 | +$badResourceFilepath = [System.IO.Path]::Combine( |
| 6 | + $resourceBasepath, |
8 | 7 | 'MSFT_WaitForAnyNoIdenticalMandatoryParameter',
|
9 | 8 | 'MSFT_WaitForAnyNoIdenticalMandatoryParameter.psm1');
|
| 9 | +$goodResourceFilepath = [System.IO.Path]::Combine($resourceBasepath,'MSFT_WaitForAny','MSFT_WaitForAny.psm1'); |
| 10 | + |
10 | 11 |
|
11 | 12 | Describe "UseIdenticalMandatoryParametersForDSC" {
|
12 |
| - Context "When a mandatory parameter is not present" { |
| 13 | + Context "When a mandatory parameters are not present" { |
13 | 14 | BeforeAll {
|
14 |
| - $violations = Invoke-ScriptAnalyzer -Path $resourceFilepath -IncludeRule $ruleName |
| 15 | + $violations = Invoke-ScriptAnalyzer -Path $badResourceFilepath -IncludeRule $ruleName |
15 | 16 | }
|
16 | 17 |
|
17 |
| - # todo add a test to check one violation per function |
18 | 18 | It "Should find a violations" {
|
19 |
| - $violations.Count | Should Be 1 |
| 19 | + $violations.Count | Should Be 4 |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | It "Should mark only the function name" {
|
23 | 23 | $violations[0].Extent.Text | Should Be 'Get-TargetResource'
|
24 | 24 | }
|
25 | 25 | }
|
| 26 | + |
| 27 | + Context "When all mandatory parameters are present" { |
| 28 | + BeforeAll { |
| 29 | + $violations = Invoke-ScriptAnalyzer -Path $goodResourceFilepath -IncludeRule $ruleName |
| 30 | + } |
| 31 | + |
| 32 | + # todo add a test to check one violation per function |
| 33 | + It "Should find a violations" { |
| 34 | + $violations.Count | Should Be 0 |
| 35 | + } |
| 36 | + } |
26 | 37 | }
|
0 commit comments