Skip to main content

pathfinder_common/
integration_testing.rs

1use std::path::Path;
2
3/// ## Important
4/// This function does nothing in production builds.
5///
6/// ## Integration testing
7/// Creates a marker file in the data directory indicating that a specific port
8/// has been assigned. This function is only active in debug builds. The file is
9/// named `{pid}_{name}_port_{value}`.
10///
11/// ## Panics
12/// The function will panic if it fails to create the marker file.
13pub fn debug_create_port_marker_file(_name: &str, _value: u16, _data_directory: &Path) {
14    #[cfg(debug_assertions)]
15    {
16        if std::env::var_os("PATHFINDER_TEST_ENABLE_MARKER_FILES").is_some() {
17            _ = std::fs::create_dir_all(_data_directory);
18            let marker_file =
19                _data_directory.join(format!("pid_{}_{}_port", std::process::id(), _name));
20            std::fs::write(&marker_file, _value.to_string()).unwrap_or_else(|_| {
21                panic!("Failed to create marker file {}", marker_file.display())
22            });
23        }
24    }
25}
26
27/// ## Important
28/// This function does nothing in production builds.
29///
30/// ## Integration testing
31/// Creates a marker file in the data directory.
32///
33/// ## Panics
34/// The function will panic if it fails to create the marker file.
35pub fn debug_create_marker_file(_name: &str, _data_directory: &Path) {
36    #[cfg(debug_assertions)]
37    {
38        if std::env::var_os("PATHFINDER_TEST_ENABLE_MARKER_FILES").is_some() {
39            _ = std::fs::create_dir_all(_data_directory);
40            let marker_file = _data_directory.join(_name);
41            std::fs::File::create(&marker_file).unwrap_or_else(|_| {
42                panic!("Failed to create marker file {}", marker_file.display())
43            });
44        }
45    }
46}