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:: 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,13 +122,9 @@ 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 ( agent_id)
127+ . join ( INSTANCE_ID_FILENAME )
139128 }
140129}
141130
@@ -156,26 +145,32 @@ mod tests {
156145 #[ test]
157146 fn basic_get_uild_path ( ) {
158147 let sa_dir = PathBuf :: from ( "/super" ) ;
159- let sub_agent_dir = PathBuf :: from ( "/sub" ) ;
160148 let storer = Storer :: new (
161149 MockLocalFile :: default ( ) ,
162150 MockDirectoryManager :: default ( ) ,
163151 sa_dir. clone ( ) ,
164- sub_agent_dir. clone ( ) ,
165152 ) ;
166153 let agent_id = AgentID :: try_from ( "test" ) . unwrap ( ) ;
167154 let path = storer. get_instance_id_path ( & agent_id) ;
168- assert_eq ! ( path, sub_agent_dir. join( "test" ) . join( "identifiers.yaml" ) ) ;
155+ assert_eq ! (
156+ path,
157+ sa_dir. join( "fleet-data-test" ) . join( "instance_id.yaml" )
158+ ) ;
169159
170160 let agent_control_id = AgentID :: AgentControl ;
171161 let path = storer. get_instance_id_path ( & agent_control_id) ;
172- assert_eq ! ( path, sa_dir. join( "identifiers.yaml" ) ) ;
162+ assert_eq ! (
163+ path,
164+ sa_dir
165+ . join( "fleet-data-agent-control" )
166+ . join( "instance_id.yaml" )
167+ ) ;
173168 }
174169
175170 #[ test]
176171 fn test_successful_write ( ) {
177172 // Data
178- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
173+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
179174 let mut file_rw = MockLocalFile :: default ( ) ;
180175 let mut dir_manager = MockDirectoryManager :: default ( ) ;
181176 let instance_id = InstanceID :: create ( ) ;
@@ -188,14 +183,14 @@ mod tests {
188183 dir_manager. should_create ( instance_id_path. parent ( ) . unwrap ( ) ) ;
189184 file_rw. should_write ( & instance_id_path, expected_file ( instance_id) ) ;
190185
191- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
186+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
192187 assert ! ( storer. set( & agent_id, & ds) . is_ok( ) ) ;
193188 }
194189
195190 #[ test]
196191 fn test_unsuccessful_write ( ) {
197192 // Data
198- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
193+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
199194 let mut file_rw = MockLocalFile :: default ( ) ;
200195 let mut dir_manager = MockDirectoryManager :: default ( ) ;
201196 let instance_id = InstanceID :: create ( ) ;
@@ -208,14 +203,14 @@ mod tests {
208203 file_rw. should_not_write ( & instance_id_path, expected_file ( instance_id) ) ;
209204 dir_manager. should_create ( instance_id_path. parent ( ) . unwrap ( ) ) ;
210205
211- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
206+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
212207 assert ! ( storer. set( & agent_id, & ds) . is_err( ) ) ;
213208 }
214209
215210 #[ test]
216211 fn test_successful_read ( ) {
217212 // Data
218- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
213+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
219214 let mut file_rw = MockLocalFile :: default ( ) ;
220215 let dir_manager = MockDirectoryManager :: default ( ) ;
221216 let instance_id = InstanceID :: create ( ) ;
@@ -234,15 +229,15 @@ mod tests {
234229 . once ( )
235230 . return_once ( |_| Ok ( expected_file ( instance_id) ) ) ;
236231
237- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
232+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
238233 let actual = storer. get ( & agent_id) ;
239234 assert ! ( actual. is_ok( ) ) ;
240235 assert_eq ! ( expected, actual. unwrap( ) ) ;
241236 }
242237
243238 #[ test]
244239 fn test_unsuccessful_read ( ) {
245- let ( agent_id, sa_path, sub_agent_path , instance_id_path) = test_data ( ) ;
240+ let ( agent_id, sa_path, instance_id_path) = test_data ( ) ;
246241 let mut file_rw = MockLocalFile :: default ( ) ;
247242 let dir_manager = MockDirectoryManager :: default ( ) ;
248243
@@ -254,7 +249,7 @@ mod tests {
254249 . once ( )
255250 . return_once ( |_| Err ( io:: Error :: other ( "some error message" ) . into ( ) ) ) ;
256251
257- let storer = Storer :: new ( file_rw, dir_manager, sa_path, sub_agent_path ) ;
252+ let storer = Storer :: new ( file_rw, dir_manager, sa_path) ;
258253 let expected = storer. get ( & agent_id) ;
259254
260255 // As said above, we are not generating the error variant here
@@ -270,12 +265,11 @@ mod tests {
270265 const HOST_ID : & str = "test-host-id" ;
271266 const FLEET_ID : & str = "test-fleet-id" ;
272267
273- fn test_data ( ) -> ( AgentID , PathBuf , PathBuf , PathBuf ) {
268+ fn test_data ( ) -> ( AgentID , PathBuf , PathBuf ) {
274269 let agent_id = AgentID :: try_from ( "test" ) . unwrap ( ) ;
275270 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)
271+ let instance_id_path = PathBuf :: from ( "/super/fleet-data-test/instance_id.yaml" ) ;
272+ ( agent_id, sa_path, instance_id_path)
279273 }
280274
281275 fn expected_file ( instance_id : InstanceID ) -> String {
0 commit comments