@@ -6,7 +6,7 @@ function Get-OperationValidation {
6
6
7
7
. DESCRIPTION
8
8
Modules which include a Diagnostics directory are inspected for
9
- Pester tests in either the "Simple" or "Comprehensive" directories .
9
+ Pester tests in either the "Simple" or "Comprehensive" subdirectories .
10
10
If files are found in those directories, they will be inspected to determine
11
11
whether they are Pester tests. If Pester tests are found, the
12
12
test names in those files will be returned.
@@ -19,38 +19,29 @@ function Get-OperationValidation {
19
19
(e.g., ping, serviceendpoint checks)
20
20
Comprehensive # comprehensive scenario tests should be placed here
21
21
22
- . PARAMETER ModuleName
23
- By default this is * which will retrieve all modules in $env:psmodulepath
24
- Additional module directories may be added. If you wish to check both
25
- $env:psmodulepath and your own specific locations, use
26
- *,<yourmodulepath>
22
+ . PARAMETER Name
23
+ One or more module names to inspect and return if they adhere to the OVF Pester test structure.
24
+
25
+ By default this is [*] which will inspect all modules in $env:PSModulePath.
26
+
27
+ . PARAMETER Path
28
+ One or more paths to search for OVF modules in. This bypasses searching the directories contained in $env:PSModulePath.
29
+
30
+ . PARAMETER LiteralPath
31
+ One or more literal paths to search for OVF modules in. This bypasses searching the directories contained in $env:PSModulePath.
32
+
33
+ Unlike the Path parameter, the value of LiteralPath is used exactly as it is typed.
34
+ No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation
35
+ marks tell PowerShell not to interpret any characters as escape sequences.
27
36
28
37
. PARAMETER TestType
29
- The type of tests to retrieve, this may be either "Simple", "Comprehensive"
30
- or Both ( "Simple,Comprehensive"). "Simple, Comprehensive" is the default.
38
+ The type of tests to retrieve, this may be either "Simple", "Comprehensive", or Both ("Simple,Comprehensive").
39
+ "Simple, Comprehensive" is the default.
31
40
32
41
. PARAMETER Version
33
- The version of the module to retrieve. If the specified, the latest version
42
+ The version of the module to retrieve. If not specified, the latest version
34
43
of the module will be retured.
35
44
36
- . EXAMPLE
37
- PS> Get-OperationValidation -ModuleName C:\temp\modules\AddNumbers
38
-
39
- Type: Simple
40
- File: addnum.tests.ps1
41
- FilePath: C:\temp\modules\AddNumbers\Diagnostics\Simple\addnum.tests.ps1
42
- Name:
43
- Add-Em
44
- Subtract em
45
- Add-Numbers
46
- Type: Comprehensive
47
- File: Comp.Adding.Tests.ps1
48
- FilePath: C:\temp\modules\AddNumbers\Diagnostics\Comprehensive\Comp.Adding.Tests.ps1
49
- Name:
50
- Comprehensive Adding Tests
51
- Comprehensive Subtracting Tests
52
- Comprehensive Examples
53
-
54
45
. PARAMETER Tag
55
46
Executes tests with specified tag parameter values. Wildcard characters and tag values that include spaces
56
47
or whitespace characters are not supported.
@@ -64,29 +55,150 @@ function Get-OperationValidation {
64
55
65
56
When you specify multiple ExcludeTag values, Get-OperationValidation omits tests that have any
66
57
of the listed tags. If you use both Tag and ExcludeTag, ExcludeTag takes precedence.
58
+
59
+ . EXAMPLE
60
+ PS> Get-OperationValidation -Name OVF.Windows.Server
61
+
62
+ Module: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2
63
+ Version: 1.0.2
64
+ Type: Simple
65
+ Tags: {}
66
+ File: LogicalDisk.tests.ps1
67
+ FilePath: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2\Diagnostics\Simple\LogicalDisk.tests.ps1
68
+ Name:
69
+ Logical Disks
70
+
71
+
72
+ Module: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2
73
+ Version: 1.0.2
74
+ Type: Simple
75
+ Tags: {}
76
+ File: Memory.tests.ps1
77
+ FilePath: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2\Diagnostics\Simple\Memory.tests.ps1
78
+ Name:
79
+ Memory
80
+
81
+
82
+ Module: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2
83
+ Version: 1.0.2
84
+ Type: Simple
85
+ Tags: {}
86
+ File: Network.tests.ps1
87
+ FilePath: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2\Diagnostics\Simple\Network.tests.ps1
88
+ Name:
89
+ Network Adapters
90
+
91
+
92
+ Module: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2
93
+ Version: 1.0.2
94
+ Type: Simple
95
+ Tags: {}
96
+ File: Services.tests.ps1
97
+ FilePath: C:\Program Files\WindowsPowerShell\Modules\OVF.Windows.Server\1.0.2\Diagnostics\Simple\Services.tests.ps1
98
+ Name:
99
+ Operating System
100
+
101
+ . EXAMPLE
102
+ PS> $tests = Get-OperationValidation
103
+
104
+ Search in all modules found in $env:PSModulePath for OVF tests.
105
+
106
+ . EXAMPLE
107
+ PS> $tests = Get-OperationValidation -Path C:\MyTests
108
+
109
+ Search for OVF modules under c:\MyTests
110
+
111
+ . EXAMPLE
112
+ PS> $simpleTests = Get-OperationValidation -ModuleName OVF.Windows.Server -TypeType Simple
113
+
114
+ Get just the simple tests in the OVF.Windows.Server module.
115
+
116
+ . EXAMPLE
117
+ $tests = Get-OperationValidation -ModuleName OVF.Windows.Server -Version 1.0.2
118
+
119
+ Get all the tests from version 1.0.2 of the OVF.Windows.Server module.
120
+
121
+ . EXAMPLE
122
+ $storageTests = Get-OperationValidation -Tag Storage
123
+
124
+ Search in all modules for OVF tests that include the tag Storage.
125
+
126
+ . EXAMPLE
127
+ $tests = Get-OperationValidation -ExcludeTag memory
128
+
129
+ Search for OVF tests that don't include the tag Memory
130
+
67
131
. LINK
68
132
Invoke-OperationValidation
69
133
70
134
#>
71
- [CmdletBinding ()]
135
+ [CmdletBinding (DefaultParameterSetName = ' ModuleName ' )]
72
136
param (
73
- [Parameter (Position = 0 )][string []]$ModuleName = " *" ,
74
- [Parameter ()][ValidateSet (" Simple" , " Comprehensive" )][string []]$TestType = @ (" Simple" , " Comprehensive" ),
75
- [Parameter ()][Version ]$Version ,
76
- [Parameter ()][string []]$Tag ,
77
- [Parameter ()][string []]$ExcludeTag
137
+ [Parameter (Position = 0 , ParameterSetName = ' ModuleName' )]
138
+ [Alias (' ModuleName' )]
139
+ [string []]$Name = ' *' ,
140
+
141
+ [parameter (
142
+ Mandatory ,
143
+ ParameterSetName = ' Path' ,
144
+ Position = 0 ,
145
+ ValueFromPipeline ,
146
+ ValueFromPipelineByPropertyName
147
+ )]
148
+ [ValidateNotNullOrEmpty ()]
149
+ [SupportsWildcards ()]
150
+ [string []]$Path ,
151
+
152
+ [parameter (
153
+ Mandatory ,
154
+ ParameterSetName = ' LiteralPath' ,
155
+ Position = 0 ,
156
+ ValueFromPipelineByPropertyName
157
+ )]
158
+ [ValidateNotNullOrEmpty ()]
159
+ [Alias (' PSPath' )]
160
+ [string []]$LiteralPath ,
161
+
162
+ [ValidateSet (' Simple' , ' Comprehensive' )]
163
+ [string []]$TestType = @ (' Simple' , ' Comprehensive' ),
164
+
165
+ [Version ]$Version ,
166
+
167
+ [string []]$Tag ,
168
+
169
+ [string []]$ExcludeTag
78
170
)
79
171
80
172
PROCESS {
81
173
Write-Progress - Activity ' Inspecting Modules' - Status ' '
82
- if ($PSBoundParameters.ContainsKey (' Version' ))
174
+
175
+ # Resolve module list either by module name, path, or literalpath
176
+ $modListParams = @ {}
177
+ switch ($PSCmdlet.ParameterSetName )
83
178
{
84
- $moduleCollection = @ (Get-ModuleList - Name $ModuleName - Version $Version )
179
+ ' ModuleName'
180
+ {
181
+ $modListParams.Name = $Name
182
+ break
183
+ }
184
+ ' Path'
185
+ {
186
+ $paths = Resolve-Path - Path $Path | Select-Object - ExpandProperty Path
187
+ $modListParams.Path = $paths
188
+ }
189
+ ' LiteralPath'
190
+ {
191
+ $paths = Resolve-Path - LiteralPath $LiteralPath | Select-Object - ExpandProperty Path
192
+ $modListParams.Path = $paths
193
+ }
85
194
}
86
- else
195
+
196
+ if ($PSBoundParameters.ContainsKey (' Version' ))
87
197
{
88
- $moduleCollection = @ (Get-ModuleList - Name $ModuleName )
198
+ $modListParams.Version = $Version
199
+ $moduleCollection = @ (Get-ModuleList - Name $Name - Version $Version )
89
200
}
201
+ $moduleCollection = @ (Get-ModuleList @modListParams )
90
202
91
203
$count = 1
92
204
$moduleCount = $moduleCollection.Count
@@ -97,10 +209,10 @@ function Get-OperationValidation {
97
209
$diagnosticsDir = Join-Path - Path $modulePath - ChildPath ' Diagnostics'
98
210
99
211
# Get the module manifest so we can pull out the version
100
- $moduleName = Split-Path - Path $modulePath - Leaf
101
- $manifestFile = Get-ChildItem - Path $modulePath - Filter " $ ( $moduleName ) .psd1"
212
+ $modName = Split-Path - Path $modulePath - Leaf
213
+ $manifestFile = Get-ChildItem - Path $modulePath - Filter " $ ( $modName ) .psd1"
102
214
if (-not $manifestFile ) {
103
- if (" $moduleName " -as [version ]) {
215
+ if (" $modName " -as [version ]) {
104
216
# We are in a "version" directory so get the actual module name from the parent directory
105
217
$parent = Split-Path - Path (Split-Path - Path $modulePath - Parent) - Leaf
106
218
$manifestFile = Get-ChildItem - Path $modulePath - Filter " $ ( $parent ) .psd1"
0 commit comments