File tree Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ VariablesToExport = @()
34
34
AliasesToExport = @ ()
35
35
36
36
# DSC resources to export from this module
37
- DscResourcesToExport = ' TestClassResource'
37
+ DscResourcesToExport = @ ( ' TestClassResource' , ' NoExport ' )
38
38
39
39
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
40
40
PrivateData = @ {
Original file line number Diff line number Diff line change @@ -74,6 +74,33 @@ class TestClassResource : BaseTestClass
74
74
}
75
75
}
76
76
77
+ [DscResource ()]
78
+ class NoExport : BaseTestClass
79
+ {
80
+ [DscProperty (Key)]
81
+ [string ] $Name
82
+
83
+ [DscProperty ()]
84
+ [string ] $Prop1
85
+
86
+ [DscProperty ()]
87
+ [string ] $EnumProp
88
+
89
+ [void ] Set()
90
+ {
91
+ }
92
+
93
+ [bool ] Test()
94
+ {
95
+ return $true
96
+ }
97
+
98
+ [NoExport ] Get()
99
+ {
100
+ return $this
101
+ }
102
+ }
103
+
77
104
function Test-World ()
78
105
{
79
106
" Hello world from PSTestModule!"
Original file line number Diff line number Diff line change @@ -71,6 +71,23 @@ Describe 'PowerShell adapter resource tests' {
71
71
$res.resources [0 ].properties.result[0 ].Prop1 | Should - Be " Property of object1"
72
72
}
73
73
74
+ It ' Export fails when class-based resource does not implement' {
75
+ $yaml = @'
76
+ $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
77
+ resources:
78
+ - name: Working with class-based resources
79
+ type: Microsoft.DSC/PowerShell
80
+ properties:
81
+ resources:
82
+ - name: Class-resource Info
83
+ type: TestClassResource/NoExport
84
+ '@
85
+ $out = $yaml | dsc config export 2>&1 | Out-String
86
+ $LASTEXITCODE | Should - Be 2
87
+ $out | Should -Not - BeNullOrEmpty
88
+ $out | Should - BeLike " *ERROR*Export method not implemented by resource 'TestClassResource/NoExport'*"
89
+ }
90
+
74
91
It ' Custom psmodulepath in config works' {
75
92
76
93
$OldPSModulePath = $env: PSModulePath
Original file line number Diff line number Diff line change @@ -475,6 +475,10 @@ function Invoke-DscOperation {
475
475
' Export' {
476
476
$t = $dscResourceInstance.GetType ()
477
477
$method = $t.GetMethod (' Export' )
478
+ if ($null -eq $method ) {
479
+ " Export method not implemented by resource '$ ( $DesiredState.Type ) '" | Write-DscTrace - Operation Error
480
+ exit 1
481
+ }
478
482
$resultArray = $method.Invoke ($null , $null )
479
483
$addToActualState = $resultArray
480
484
}
You can’t perform that action at this time.
0 commit comments