File tree 2 files changed +28
-4
lines changed
2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,23 @@ Describe 'PowerShell adapter resource tests' {
33
33
$res.results [0 ].result.actualState.result[0 ].properties.EnumProp | Should - BeExactly ' Expected'
34
34
}
35
35
36
+ It ' Get does not work on config when module does not exist' {
37
+
38
+ $yaml = @'
39
+ $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
40
+ resources:
41
+ - name: Working with class-based resources
42
+ type: Microsoft.DSC/PowerShell
43
+ properties:
44
+ resources:
45
+ - name: Class-resource Info
46
+ type: TestClassResourceNotExist/TestClassResourceNotExist
47
+ '@
48
+ $yaml | dsc - l trace config get -f - 2> " $TestDrive /tracing.txt"
49
+ $LASTEXITCODE | Should - Be 2
50
+ " $TestDrive /tracing.txt" | Should - FileContentMatch ' DSC resource TestClassResourceNotExist/TestClassResourceNotExist module not found.'
51
+ }
52
+
36
53
It ' Test works on config with class-based resources' {
37
54
38
55
$r = Get-Content - Raw $pwshConfigPath | dsc config test -f -
Original file line number Diff line number Diff line change @@ -148,11 +148,18 @@ switch ($Operation) {
148
148
exit 1
149
149
}
150
150
151
+ # get unique module names from the desiredState input
152
+ $moduleInput = $desiredState | Select-Object - ExpandProperty Type | Sort-Object - Unique
153
+
154
+ # refresh the cache with the modules that are available on the system
151
155
$dscResourceCache = Invoke-DscCacheRefresh - module $dscResourceModules
152
- if ($dscResourceCache.count -lt $dscResourceModules.count ) {
153
- $trace = @ {' Debug' = ' ERROR: DSC resource module not found.' } | ConvertTo-Json - Compress
154
- $host.ui.WriteErrorLine ($trace )
155
- exit 1
156
+
157
+ # check if all the desired modules are in the cache
158
+ $moduleInput | ForEach-Object {
159
+ if ($dscResourceCache.type -notcontains $_ ) {
160
+ (' DSC resource {0} module not found.' -f $_ ) | Write-DscTrace - Operation Error
161
+ exit 1
162
+ }
156
163
}
157
164
158
165
foreach ($ds in $desiredState ) {
You can’t perform that action at this time.
0 commit comments