11use super :: getter:: Identifiers ;
22use crate :: agent_control:: agent_id:: AgentID ;
3- use crate :: agent_control:: defaults:: IDENTIFIERS_FILENAME ;
3+ use crate :: agent_control:: defaults:: { FOLDER_NAME_FLEET_DATA , INSTANCE_ID_FILENAME } ;
44use crate :: opamp:: instance_id:: getter:: DataStored ;
55use crate :: opamp:: instance_id:: storer:: InstanceIDStorer ;
66use fs:: LocalFile ;
2020 file_rw : F ,
2121 dir_manager : D ,
2222 agent_control_remote_dir : PathBuf ,
23- agent_remote_dir : PathBuf ,
2423}
2524
2625#[ derive( thiserror:: Error , Debug ) ]
@@ -67,17 +66,11 @@ where
6766 D : DirectoryManager ,
6867 F : FileWriter + FileReader ,
6968{
70- pub fn new (
71- file_rw : F ,
72- dir_manager : D ,
73- agent_control_remote_dir : PathBuf ,
74- agent_remote_dir : PathBuf ,
75- ) -> Self {
69+ pub fn new ( file_rw : F , dir_manager : D , agent_control_remote_dir : PathBuf ) -> Self {
7670 Self {
7771 file_rw,
7872 dir_manager,
7973 agent_control_remote_dir,
80- agent_remote_dir,
8174 }
8275 }
8376}
@@ -129,19 +122,17 @@ where
129122 }
130123
131124 fn get_instance_id_path ( & self , agent_id : & AgentID ) -> PathBuf {
132- if agent_id == & AgentID :: AgentControl {
133- self . agent_control_remote_dir . join ( IDENTIFIERS_FILENAME )
134- } else {
135- self . agent_remote_dir
136- . join ( agent_id)
137- . join ( "identifiers.yaml" )
138- }
125+ self . agent_control_remote_dir
126+ . join ( FOLDER_NAME_FLEET_DATA )
127+ . join ( agent_id)
128+ . join ( INSTANCE_ID_FILENAME )
139129 }
140130}
141131
142132#[ cfg( test) ]
143133mod tests {
144134 use crate :: agent_control:: agent_id:: AgentID ;
135+ use crate :: agent_control:: defaults:: { FOLDER_NAME_FLEET_DATA , INSTANCE_ID_FILENAME } ;
145136 use crate :: opamp:: instance_id:: InstanceID ;
146137 use crate :: opamp:: instance_id:: getter:: DataStored ;
147138 use crate :: opamp:: instance_id:: on_host:: getter:: Identifiers ;
@@ -156,26 +147,35 @@ mod tests {
156147 #[ test]
157148 fn basic_get_uild_path ( ) {
158149 let sa_dir = PathBuf :: from ( "/super" ) ;
159- let sub_agent_dir = PathBuf :: from ( "/sub" ) ;
160150 let storer = Storer :: new (
161151 MockLocalFile :: default ( ) ,
162152 MockDirectoryManager :: default ( ) ,
163153 sa_dir. clone ( ) ,
164- sub_agent_dir. clone ( ) ,
165154 ) ;
166155 let agent_id = AgentID :: try_from ( "test" ) . unwrap ( ) ;
167156 let path = storer. get_instance_id_path ( & agent_id) ;
168- assert_eq ! ( path, sub_agent_dir. join( "test" ) . join( "identifiers.yaml" ) ) ;
157+ assert_eq ! (
158+ path,
159+ sa_dir
160+ . join( FOLDER_NAME_FLEET_DATA )
161+ . join( "test" )
162+ . join( INSTANCE_ID_FILENAME )
163+ ) ;
169164
170165 let agent_control_id = AgentID :: AgentControl ;
171166 let path = storer. get_instance_id_path ( & agent_control_id) ;
172- assert_eq ! ( path, sa_dir. join( "identifiers.yaml" ) ) ;
167+ assert_eq ! (
168+ path,
169+ sa_dir
170+ . join( "fleet-data/agent-control" )
171+ . join( INSTANCE_ID_FILENAME )
172+ ) ;
173173 }
174174
175175 #[ test]
176176 fn test_successful_write ( ) {
177177 // Data
178- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
178+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
179179 let mut file_rw = MockLocalFile :: default ( ) ;
180180 let mut dir_manager = MockDirectoryManager :: default ( ) ;
181181 let instance_id = InstanceID :: create ( ) ;
@@ -188,14 +188,14 @@ mod tests {
188188 dir_manager. should_create ( instance_id_path. parent ( ) . unwrap ( ) ) ;
189189 file_rw. should_write ( & instance_id_path, expected_file ( instance_id) ) ;
190190
191- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
191+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
192192 assert ! ( storer. set( & agent_id, & ds) . is_ok( ) ) ;
193193 }
194194
195195 #[ test]
196196 fn test_unsuccessful_write ( ) {
197197 // Data
198- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
198+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
199199 let mut file_rw = MockLocalFile :: default ( ) ;
200200 let mut dir_manager = MockDirectoryManager :: default ( ) ;
201201 let instance_id = InstanceID :: create ( ) ;
@@ -208,14 +208,14 @@ mod tests {
208208 file_rw. should_not_write ( & instance_id_path, expected_file ( instance_id) ) ;
209209 dir_manager. should_create ( instance_id_path. parent ( ) . unwrap ( ) ) ;
210210
211- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
211+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
212212 assert ! ( storer. set( & agent_id, & ds) . is_err( ) ) ;
213213 }
214214
215215 #[ test]
216216 fn test_successful_read ( ) {
217217 // Data
218- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
218+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
219219 let mut file_rw = MockLocalFile :: default ( ) ;
220220 let dir_manager = MockDirectoryManager :: default ( ) ;
221221 let instance_id = InstanceID :: create ( ) ;
@@ -234,15 +234,15 @@ mod tests {
234234 . once ( )
235235 . return_once ( |_| Ok ( expected_file ( instance_id) ) ) ;
236236
237- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
237+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
238238 let actual = storer. get ( & agent_id) ;
239239 assert ! ( actual. is_ok( ) ) ;
240240 assert_eq ! ( expected, actual. unwrap( ) ) ;
241241 }
242242
243243 #[ test]
244244 fn test_unsuccessful_read ( ) {
245- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
245+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
246246 let mut file_rw = MockLocalFile :: default ( ) ;
247247 let dir_manager = MockDirectoryManager :: default ( ) ;
248248
@@ -254,7 +254,7 @@ mod tests {
254254 . once ( )
255255 . return_once ( |_| Err ( io:: Error :: other ( "some error message" ) . into ( ) ) ) ;
256256
257- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
257+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
258258 let expected = storer. get ( & agent_id) ;
259259
260260 // As said above, we are not generating the error variant here
@@ -270,12 +270,11 @@ mod tests {
270270 const HOST_ID : & str = "test-host-id" ;
271271 const FLEET_ID : & str = "test-fleet-id" ;
272272
273- fn test_data ( ) -> ( AgentID , PathBuf , PathBuf , PathBuf ) {
273+ fn test_data ( ) -> ( AgentID , PathBuf , PathBuf ) {
274274 let agent_id = AgentID :: try_from ( "test" ) . unwrap ( ) ;
275275 let sa_path = PathBuf :: from ( "/super" ) ;
276- let sub_agent_path = PathBuf :: from ( "/sub" ) ;
277- let instance_id_path = PathBuf :: from ( "/sub/test/identifiers.yaml" ) ;
278- ( agent_id, sa_path, sub_agent_path, instance_id_path)
276+ let instance_id_path = PathBuf :: from ( "/super/fleet-data/test/instance_id.yaml" ) ;
277+ ( agent_id, sa_path, instance_id_path)
279278 }
280279
281280 fn expected_file ( instance_id : InstanceID ) -> String {
0 commit comments