@@ -95,8 +95,7 @@ impl InfraConfigGenerator {
9595 } ;
9696
9797 for ( agent_id, _) in sub_agents_cfg. agents {
98- let infra_values_persister =
99- ValuesPersisterFile :: new ( self . local_dir . join ( SUB_AGENT_DIR ) ) ;
98+ let infra_values_persister = ValuesPersisterFile :: new ( self . local_dir . clone ( ) ) ;
10099 infra_values_persister
101100 . persist_values_file (
102101 & agent_id,
@@ -124,7 +123,7 @@ impl InfraConfigGenerator {
124123 let config_migrator = ConfigMigrator :: new (
125124 ConfigConverter :: default ( ) ,
126125 AgentConfigGetter :: new ( sa_local_config_loader) ,
127- ValuesPersisterFile :: new ( self . local_dir . join ( SUB_AGENT_DIR ) ) ,
126+ ValuesPersisterFile :: new ( self . local_dir . clone ( ) ) ,
128127 ) ;
129128
130129 let legacy_config_renamer = LegacyConfigRenamer :: default ( ) ;
@@ -167,7 +166,12 @@ impl InfraConfigGenerator {
167166#[ cfg( test) ]
168167mod tests {
169168 use super :: * ;
169+ use crate :: agent_control:: defaults:: {
170+ AGENT_CONTROL_ID , FOLDER_NAME_LOCAL_DATA , STORE_KEY_LOCAL_DATA_CONFIG ,
171+ } ;
172+ use crate :: opamp:: instance_id:: on_host:: storer:: build_config_name;
170173 use std:: fs;
174+ use std:: fs:: create_dir_all;
171175 use tempfile:: TempDir ;
172176
173177 const INITIAL_INFRA_CONFIG : & str = r#"
@@ -185,20 +189,27 @@ agents:
185189 agent_type: "newrelic/com.newrelic.infrastructure:0.1.0"
186190"# ;
187191
188- const INFRA_AGENT_VALUES : & str = "fleet/agents.d/ infra-test/values/values .yaml" ;
192+ const INFRA_AGENT_VALUES : & str = "local-data/ infra-test/local_config .yaml" ;
189193
190194 #[ cfg( target_family = "unix" ) ] //TODO This should be removed when Windows support is added (DirectoryManager unimplemented)
191195 #[ test]
192196 fn test_migrate_old_infra_config ( ) {
193197 // Create a temporary directory
194198 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
195199 let infra_file_path = temp_dir. path ( ) . join ( "newrelic-infra.yml" ) ;
196- let agents_file_path = temp_dir. path ( ) . join ( "config.yaml" ) ;
197-
200+ let agents_file_path = temp_dir
201+ . path ( )
202+ . join ( FOLDER_NAME_LOCAL_DATA )
203+ . join ( AGENT_CONTROL_ID ) ;
204+ create_dir_all ( & agents_file_path) . unwrap ( ) ;
198205 // Emulate the existence of the file by creating it
199206 fs:: write ( & infra_file_path, INITIAL_INFRA_CONFIG ) . unwrap ( ) ;
200207
201- fs:: write ( & agents_file_path, AGENTS_CONFIG ) . unwrap ( ) ;
208+ fs:: write (
209+ agents_file_path. join ( build_config_name ( STORE_KEY_LOCAL_DATA_CONFIG ) ) ,
210+ AGENTS_CONFIG ,
211+ )
212+ . unwrap ( ) ;
202213
203214 // Format the string using dynamic file path
204215 let config_mapping = format ! (
@@ -254,9 +265,17 @@ config_agent:
254265 #[ test]
255266 fn test_generate_new_infra_config ( ) {
256267 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
257- let agents_file_path = temp_dir. path ( ) . join ( "config.yaml" ) ;
258-
259- fs:: write ( & agents_file_path, AGENTS_CONFIG ) . unwrap ( ) ;
268+ let agents_file_path = temp_dir
269+ . path ( )
270+ . join ( FOLDER_NAME_LOCAL_DATA )
271+ . join ( AGENT_CONTROL_ID ) ;
272+ create_dir_all ( & agents_file_path) . unwrap ( ) ;
273+
274+ fs:: write (
275+ agents_file_path. join ( build_config_name ( STORE_KEY_LOCAL_DATA_CONFIG ) ) ,
276+ AGENTS_CONFIG ,
277+ )
278+ . unwrap ( ) ;
260279
261280 let infra_config_generator = InfraConfigGenerator :: new (
262281 temp_dir. path ( ) . to_path_buf ( ) ,
0 commit comments