1
- use std:: fs:: File ;
2
- use std:: io:: Write ;
3
- use std:: path:: { Path , PathBuf } ;
4
- use std:: process:: Command ;
5
- use std:: { env, io} ;
6
-
7
1
use log:: { debug, info, LevelFilter } ;
8
2
9
3
use super :: tracker_container:: TrackerContainer ;
10
4
use crate :: e2e:: docker:: RunOptions ;
11
5
use crate :: e2e:: logs_parser:: RunningServices ;
12
- use crate :: e2e:: temp_dir :: Handler ;
6
+ use crate :: e2e:: tracker_checker :: { self } ;
13
7
14
8
/* code-review:
15
9
- We use always the same docker image name. Should we use a random image name (tag)?
@@ -19,10 +13,9 @@ use crate::e2e::temp_dir::Handler;
19
13
Should we remove the image too?
20
14
*/
21
15
22
- pub const NUMBER_OF_ARGUMENTS : usize = 2 ;
16
+ const NUMBER_OF_ARGUMENTS : usize = 2 ;
23
17
const CONTAINER_IMAGE : & str = "torrust-tracker:local" ;
24
18
const CONTAINER_NAME_PREFIX : & str = "tracker_" ;
25
- const TRACKER_CHECKER_CONFIG_FILE : & str = "tracker_checker.json" ;
26
19
27
20
pub struct Arguments {
28
21
pub tracker_config_path : String ,
@@ -63,14 +56,10 @@ pub fn run() {
63
56
64
57
assert_there_is_at_least_one_service_per_type ( & running_services) ;
65
58
66
- let temp_dir = create_temp_dir ( ) ;
67
-
68
- let tracker_checker_config_path =
69
- create_tracker_checker_config_file ( & running_services, temp_dir. temp_dir . path ( ) , TRACKER_CHECKER_CONFIG_FILE ) ;
59
+ let tracker_checker_config =
60
+ serde_json:: to_string_pretty ( & running_services) . expect ( "Running services should be serialized into JSON" ) ;
70
61
71
- // todo: inject the configuration with an env variable so that we don't have
72
- // to create the temporary directory/file.
73
- run_tracker_checker ( & tracker_checker_config_path) . expect ( "All tracker services should be running correctly" ) ;
62
+ tracker_checker:: run ( & tracker_checker_config) . expect ( "All tracker services should be running correctly" ) ;
74
63
75
64
// More E2E tests could be added here in the future.
76
65
// For example: `cargo test ...` for only E2E tests, using this shared test env.
@@ -128,19 +117,6 @@ fn read_file(path: &str) -> String {
128
117
std:: fs:: read_to_string ( path) . unwrap_or_else ( |_| panic ! ( "Can't read file {path}" ) )
129
118
}
130
119
131
- fn create_temp_dir ( ) -> Handler {
132
- debug ! (
133
- "Current dir: {:?}" ,
134
- env:: current_dir( ) . expect( "It should return the current dir" )
135
- ) ;
136
-
137
- let temp_dir_handler = Handler :: new ( ) . expect ( "A temp dir should be created" ) ;
138
-
139
- info ! ( "Temp dir created: {:?}" , temp_dir_handler. temp_dir) ;
140
-
141
- temp_dir_handler
142
- }
143
-
144
120
fn assert_there_is_at_least_one_service_per_type ( running_services : & RunningServices ) {
145
121
assert ! (
146
122
!running_services. udp_trackers. is_empty( ) ,
@@ -155,64 +131,3 @@ fn assert_there_is_at_least_one_service_per_type(running_services: &RunningServi
155
131
"At least one Health Check should be enabled in E2E tests configuration"
156
132
) ;
157
133
}
158
-
159
- fn create_tracker_checker_config_file ( running_services : & RunningServices , config_path : & Path , config_name : & str ) -> PathBuf {
160
- let tracker_checker_config =
161
- serde_json:: to_string_pretty ( & running_services) . expect ( "Running services should be serialized into JSON" ) ;
162
-
163
- let mut tracker_checker_config_path = PathBuf :: from ( & config_path) ;
164
- tracker_checker_config_path. push ( config_name) ;
165
-
166
- write_tracker_checker_config_file ( & tracker_checker_config_path, & tracker_checker_config) ;
167
-
168
- tracker_checker_config_path
169
- }
170
-
171
- fn write_tracker_checker_config_file ( config_file_path : & Path , config : & str ) {
172
- info ! (
173
- "Writing Tracker Checker configuration file: {:?} \n {config}" ,
174
- config_file_path
175
- ) ;
176
-
177
- let mut file = File :: create ( config_file_path) . expect ( "Tracker checker config file to be created" ) ;
178
-
179
- file. write_all ( config. as_bytes ( ) )
180
- . expect ( "Tracker checker config file to be written" ) ;
181
- }
182
-
183
- /// Runs the Tracker Checker.
184
- ///
185
- /// For example:
186
- ///
187
- /// ```text
188
- /// cargo run --bin tracker_checker "./share/default/config/tracker_checker.json"
189
- /// ```
190
- ///
191
- /// # Errors
192
- ///
193
- /// Will return an error if the tracker checker fails.
194
- ///
195
- /// # Panics
196
- ///
197
- /// Will panic if the config path is not a valid string.
198
- pub fn run_tracker_checker ( config_path : & Path ) -> io:: Result < ( ) > {
199
- info ! (
200
- "Running Tracker Checker: cargo run --bin tracker_checker -- --config-path \" {}\" " ,
201
- config_path. display( )
202
- ) ;
203
-
204
- let path = config_path. to_str ( ) . expect ( "The path should be a valid string" ) ;
205
-
206
- let status = Command :: new ( "cargo" )
207
- . args ( [ "run" , "--bin" , "tracker_checker" , "--" , "--config-path" , path] )
208
- . status ( ) ?;
209
-
210
- if status. success ( ) {
211
- Ok ( ( ) )
212
- } else {
213
- Err ( io:: Error :: new (
214
- io:: ErrorKind :: Other ,
215
- format ! ( "Failed to run Tracker Checker with config file {path}" ) ,
216
- ) )
217
- }
218
- }
0 commit comments