File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 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' {
3333 $res.results [0 ].result.actualState.result[0 ].properties.EnumProp | Should - BeExactly ' Expected'
3434 }
3535
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+
3653 It ' Test works on config with class-based resources' {
3754
3855 $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) {
148148 exit 1
149149 }
150150
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
151155 $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+ }
156163 }
157164
158165 foreach ($ds in $desiredState ) {
You can’t perform that action at this time.
0 commit comments