@@ -91,20 +91,20 @@ where
9191 }
9292 } ;
9393
94- let config_map: Option < ConfigurationMap > = match msg_remote_config. config {
94+ let config_map: ConfigurationMap = match msg_remote_config. config {
9595 Some ( msg_config_map) => msg_config_map
9696 . try_into ( )
9797 . inspect_err ( |err : & OpampRemoteConfigError | {
9898 state = ConfigState :: Failed {
9999 error_message : format ! ( "Invalid remote config format: {err}" ) ,
100100 } ;
101101 } )
102- . ok ( ) ,
102+ . unwrap_or_default ( ) ,
103103 None => {
104104 state = ConfigState :: Failed {
105105 error_message : "Config missing" . into ( ) ,
106106 } ;
107- None
107+ ConfigurationMap :: default ( )
108108 }
109109 } ;
110110
@@ -264,7 +264,9 @@ pub(crate) mod tests {
264264 use crate :: opamp:: remote_config:: signature:: {
265265 ED25519 , SIGNATURE_CUSTOM_CAPABILITY , SIGNATURE_CUSTOM_MESSAGE_TYPE ,
266266 } ;
267- use crate :: opamp:: remote_config:: { ConfigurationMap , OpampRemoteConfig } ;
267+ use crate :: opamp:: remote_config:: {
268+ ConfigurationMap , DEFAULT_AGENT_CONFIG_IDENTIFIER , OpampRemoteConfig ,
269+ } ;
268270 use opamp_client:: opamp:: proto:: { AgentConfigFile , AgentConfigMap , AgentRemoteConfig } ;
269271 use std:: collections:: HashMap ;
270272 use std:: time:: Duration ;
@@ -338,15 +340,15 @@ pub(crate) mod tests {
338340 let ( valid_remote_config_map, expected_remote_config_map) = (
339341 AgentConfigMap {
340342 config_map : HashMap :: from ( [ (
341- "my-config" . to_string ( ) ,
343+ DEFAULT_AGENT_CONFIG_IDENTIFIER . to_string ( ) ,
342344 AgentConfigFile {
343345 body : "enable_proces_metrics: true" . as_bytes ( ) . to_vec ( ) ,
344346 content_type : "" . to_string ( ) ,
345347 } ,
346348 ) ] ) ,
347349 } ,
348350 ConfigurationMap :: new ( HashMap :: from ( [ (
349- "my-config" . to_string ( ) ,
351+ DEFAULT_AGENT_CONFIG_IDENTIFIER . to_string ( ) ,
350352 "enable_proces_metrics: true" . to_string ( ) ,
351353 ) ] ) ) ,
352354 ) ;
@@ -356,7 +358,7 @@ pub(crate) mod tests {
356358 opamp_msg : Option < MessageData > , // using option here to allow taking the ownership of the MessageData which cannot be cloned.
357359 expected_remote_config_hash : Hash ,
358360 expected_remote_config_state : ConfigState ,
359- expected_remote_config_config_map : Option < ConfigurationMap > ,
361+ expected_remote_config_config_map : ConfigurationMap ,
360362 expected_signature : Option < Signatures > ,
361363 }
362364 impl TestCase {
@@ -403,7 +405,7 @@ pub(crate) mod tests {
403405 } ) ,
404406 ..Default :: default ( )
405407 } ) ,
406- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
408+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
407409 expected_remote_config_hash: Hash :: from( valid_hash) ,
408410 expected_remote_config_state: ConfigState :: Applying ,
409411 expected_signature: None ,
@@ -425,7 +427,7 @@ pub(crate) mod tests {
425427 } ) ,
426428 ..Default :: default ( )
427429 } ) ,
428- expected_remote_config_config_map: None ,
430+ expected_remote_config_config_map: ConfigurationMap :: default ( ) ,
429431 expected_remote_config_hash: Hash :: from( valid_hash) ,
430432 expected_remote_config_state: ConfigState :: Failed {
431433 error_message: "Invalid remote config format: invalid UTF-8 sequence: `invalid utf-8 sequence of 1 bytes from index 0`" . into( ) ,
@@ -441,7 +443,7 @@ pub(crate) mod tests {
441443 } ) ,
442444 ..Default :: default ( )
443445 } ) ,
444- expected_remote_config_config_map: None ,
446+ expected_remote_config_config_map: ConfigurationMap :: default ( ) ,
445447 expected_remote_config_hash: Hash :: from( valid_hash) ,
446448 expected_remote_config_state: ConfigState :: Failed {
447449 error_message: "Config missing" . into( ) ,
@@ -457,7 +459,7 @@ pub(crate) mod tests {
457459 } ) ,
458460 ..Default :: default ( )
459461 } ) ,
460- expected_remote_config_config_map: None ,
462+ expected_remote_config_config_map: ConfigurationMap :: default ( ) ,
461463 expected_remote_config_hash: Hash :: default ( ) ,
462464 expected_remote_config_state: ConfigState :: Failed {
463465 error_message: "Config missing" . into( ) ,
@@ -473,7 +475,7 @@ pub(crate) mod tests {
473475 } ) ,
474476 ..Default :: default ( )
475477 } ) ,
476- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
478+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
477479 expected_remote_config_hash: Hash :: default ( ) ,
478480 expected_remote_config_state: ConfigState :: Failed {
479481 error_message: "Invalid hash: invalid utf-8 sequence of 1 bytes from index 0" . into( ) ,
@@ -490,22 +492,23 @@ pub(crate) mod tests {
490492 custom_message: Some ( CustomMessage {
491493 capability: SIGNATURE_CUSTOM_CAPABILITY . to_string( ) ,
492494 r#type: SIGNATURE_CUSTOM_MESSAGE_TYPE . to_string( ) ,
493- data: r#" {
494- "unique" : [{
495+ data: serde_json :: json! ( {
496+ DEFAULT_AGENT_CONFIG_IDENTIFIER : [ {
495497 "signature" : "fake config" ,
496498 "signingAlgorithm" : "ED25519" ,
497499 "keyId" : "fake keyid"
498500 } ]
499- }"#
501+ } )
502+ . to_string( )
500503 . as_bytes( )
501504 . to_vec( ) ,
502505 } ) ,
503506 ..Default :: default ( )
504507 } ) ,
505- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
508+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
506509 expected_remote_config_hash: Hash :: from( valid_hash) ,
507510 expected_remote_config_state: ConfigState :: Applying ,
508- expected_signature: Some ( Signatures :: new_unique (
511+ expected_signature: Some ( Signatures :: new_default (
509512 "fake config" ,
510513 ED25519 ,
511514 "fake keyid" ,
@@ -533,7 +536,7 @@ pub(crate) mod tests {
533536 } ) ,
534537 ..Default :: default ( )
535538 } ) ,
536- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
539+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
537540 expected_remote_config_hash: Hash :: from( valid_hash) ,
538541 expected_remote_config_state: ConfigState :: Applying ,
539542 expected_signature: None ,
@@ -560,7 +563,7 @@ pub(crate) mod tests {
560563 } ) ,
561564 ..Default :: default ( )
562565 } ) ,
563- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
566+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
564567 expected_remote_config_hash: Hash :: from( valid_hash) ,
565568 expected_remote_config_state: ConfigState :: Applying ,
566569 expected_signature: None ,
@@ -579,7 +582,7 @@ pub(crate) mod tests {
579582 } ) ,
580583 ..Default :: default ( )
581584 } ) ,
582- expected_remote_config_config_map: Some ( expected_remote_config_map. clone( ) ) ,
585+ expected_remote_config_config_map: expected_remote_config_map. clone( ) ,
583586 expected_remote_config_hash: Hash :: from( valid_hash) ,
584587 expected_remote_config_state: ConfigState :: Failed {
585588 error_message: "Invalid remote config signature format: expected value at line 1 column 1" . into( ) ,
0 commit comments