@@ -7,6 +7,7 @@ use schemars::JsonSchema;
77use serde:: { Deserialize , Serialize } ;
88use serde_json:: Value ;
99use std:: collections:: HashMap ;
10+ use tracing:: debug;
1011
1112use super :: { command_resource, dscerror, invoke_result:: { ExportResult , GetResult , ResolveResult , ResourceTestResponse , SetResult , TestResult , ValidateResult } , resource_manifest:: import_manifest} ;
1213
@@ -187,6 +188,7 @@ pub trait Invoke {
187188
188189impl Invoke for DscResource {
189190 fn get ( & self , filter : & str ) -> Result < GetResult , DscError > {
191+ debug ! ( "Invoking get for resource: {}" , self . type_name) ;
190192 match & self . implemented_as {
191193 ImplementedAs :: Custom ( _custom) => {
192194 Err ( DscError :: NotImplemented ( "get custom resources" . to_string ( ) ) )
@@ -202,6 +204,7 @@ impl Invoke for DscResource {
202204 }
203205
204206 fn set ( & self , desired : & str , skip_test : bool , execution_type : & ExecutionKind ) -> Result < SetResult , DscError > {
207+ debug ! ( "Invoking set for resource: {}" , self . type_name) ;
205208 match & self . implemented_as {
206209 ImplementedAs :: Custom ( _custom) => {
207210 Err ( DscError :: NotImplemented ( "set custom resources" . to_string ( ) ) )
@@ -217,6 +220,7 @@ impl Invoke for DscResource {
217220 }
218221
219222 fn test ( & self , expected : & str ) -> Result < TestResult , DscError > {
223+ debug ! ( "Invoking test for resource: {}" , self . type_name) ;
220224 match & self . implemented_as {
221225 ImplementedAs :: Custom ( _custom) => {
222226 Err ( DscError :: NotImplemented ( "test custom resources" . to_string ( ) ) )
@@ -230,7 +234,15 @@ impl Invoke for DscResource {
230234 let resource_manifest = import_manifest ( manifest. clone ( ) ) ?;
231235 if resource_manifest. test . is_none ( ) {
232236 let get_result = self . get ( expected) ?;
233- let desired_state = serde_json:: from_str ( expected) ?;
237+ let desired_state = if self . kind == Kind :: Import {
238+ let config = self . resolve ( expected) ?. configuration ;
239+ // TODO: implement way to resolve entire config doc including expressions and parameters
240+ // as the raw configuration (desired state) won't match the result, also convert the desired
241+ // state to a TestResult so the comparison is consistent
242+ serde_json:: to_value ( config[ "resources" ] . clone ( ) ) ?
243+ } else {
244+ serde_json:: from_str ( expected) ?
245+ } ;
234246 let actual_state = match get_result {
235247 GetResult :: Group ( results) => {
236248 let mut result_array: Vec < Value > = Vec :: new ( ) ;
@@ -245,7 +257,7 @@ impl Invoke for DscResource {
245257 } ;
246258 let diff_properties = get_diff ( & desired_state, & actual_state) ;
247259 let test_result = TestResult :: Resource ( ResourceTestResponse {
248- desired_state : serde_json :: from_str ( expected ) ? ,
260+ desired_state,
249261 actual_state,
250262 in_desired_state : diff_properties. is_empty ( ) ,
251263 diff_properties,
@@ -260,6 +272,7 @@ impl Invoke for DscResource {
260272 }
261273
262274 fn delete ( & self , filter : & str ) -> Result < ( ) , DscError > {
275+ debug ! ( "Invoking delete for resource: {}" , self . type_name) ;
263276 match & self . implemented_as {
264277 ImplementedAs :: Custom ( _custom) => {
265278 Err ( DscError :: NotImplemented ( "set custom resources" . to_string ( ) ) )
@@ -275,6 +288,7 @@ impl Invoke for DscResource {
275288 }
276289
277290 fn validate ( & self , config : & str ) -> Result < ValidateResult , DscError > {
291+ debug ! ( "Invoking validate for resource: {}" , self . type_name) ;
278292 match & self . implemented_as {
279293 ImplementedAs :: Custom ( _custom) => {
280294 Err ( DscError :: NotImplemented ( "validate custom resources" . to_string ( ) ) )
@@ -290,6 +304,7 @@ impl Invoke for DscResource {
290304 }
291305
292306 fn schema ( & self ) -> Result < String , DscError > {
307+ debug ! ( "Invoking schema for resource: {}" , self . type_name) ;
293308 match & self . implemented_as {
294309 ImplementedAs :: Custom ( _custom) => {
295310 Err ( DscError :: NotImplemented ( "schema custom resources" . to_string ( ) ) )
@@ -305,6 +320,7 @@ impl Invoke for DscResource {
305320 }
306321
307322 fn export ( & self , input : & str ) -> Result < ExportResult , DscError > {
323+ debug ! ( "Invoking export for resource: {}" , self . type_name) ;
308324 let Some ( manifest) = & self . manifest else {
309325 return Err ( DscError :: MissingManifest ( self . type_name . clone ( ) ) ) ;
310326 } ;
@@ -313,6 +329,7 @@ impl Invoke for DscResource {
313329 }
314330
315331 fn resolve ( & self , input : & str ) -> Result < ResolveResult , DscError > {
332+ debug ! ( "Invoking resolve for resource: {}" , self . type_name) ;
316333 let Some ( manifest) = & self . manifest else {
317334 return Err ( DscError :: MissingManifest ( self . type_name . clone ( ) ) ) ;
318335 } ;
0 commit comments