Skip to content

Commit f459446

Browse files
committed
refactor: reorganize TestEnvironment method order and improve API consistency
- Remove deprecated new_and_init() method to reduce API surface - Move with_ssh_user_and_init() method to public API position - Make with_ssh_user() and init() methods private as implementation details - Improve documentation flow by placing public methods before private ones - Maintain consistent two-phase construction pattern (construct + init) - No functional changes, purely organizational refactoring
1 parent cdc2b4d commit f459446

File tree

1 file changed

+38
-64
lines changed

1 file changed

+38
-64
lines changed

src/e2e/environment.rs

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,6 @@ pub struct TestEnvironment {
8888
}
8989

9090
impl TestEnvironment {
91-
/// Creates and initializes a new test environment in one step
92-
///
93-
/// This is a convenience method that combines `new()` and `init()`.
94-
/// Use this when you want the full setup in one call.
95-
///
96-
/// # Arguments
97-
///
98-
/// * `keep_env` - Whether to keep the environment after tests complete
99-
/// * `templates_dir` - Path to the templates directory
100-
/// * `instance_name` - Name for the instance to be deployed
101-
///
102-
/// # Errors
103-
///
104-
/// Returns an error if:
105-
/// - Construction fails (see `new()` for details)
106-
/// - Initialization fails (see `init()` for details)
107-
pub fn new_and_init(
108-
keep_env: bool,
109-
templates_dir: impl Into<std::path::PathBuf>,
110-
instance_name: InstanceName,
111-
) -> Result<Self, TestEnvironmentError> {
112-
let env = Self::new(keep_env, templates_dir, instance_name)?;
113-
env.init()?;
114-
Ok(env)
115-
}
116-
11791
/// Creates a new test environment with configuration and services
11892
///
11993
/// This method only performs basic construction without side effects.
@@ -151,6 +125,42 @@ impl TestEnvironment {
151125
)
152126
}
153127

128+
/// Creates and initializes a new test environment with custom SSH user in one step
129+
///
130+
/// This is a convenience method that combines `with_ssh_user()` and `init()`.
131+
/// Use this when you want the full setup in one call.
132+
///
133+
/// # Arguments
134+
///
135+
/// * `keep_env` - Whether to keep the environment after tests complete
136+
/// * `templates_dir` - Path to the templates directory
137+
/// * `ssh_user` - SSH username to use for connections
138+
/// * `instance_name` - Name for the instance to be deployed
139+
/// * `environment_type` - The type of test environment (Container or `VirtualMachine`)
140+
///
141+
/// # Errors
142+
///
143+
/// Returns an error if:
144+
/// - Construction fails (see `with_ssh_user()` for details)
145+
/// - Initialization fails (see `init()` for details)
146+
pub fn with_ssh_user_and_init(
147+
keep_env: bool,
148+
templates_dir: impl Into<std::path::PathBuf>,
149+
ssh_user: &str,
150+
instance_name: InstanceName,
151+
environment_type: TestEnvironmentType,
152+
) -> Result<Self, TestEnvironmentError> {
153+
let env = Self::with_ssh_user(
154+
keep_env,
155+
templates_dir,
156+
ssh_user,
157+
instance_name,
158+
environment_type,
159+
)?;
160+
env.init()?;
161+
Ok(env)
162+
}
163+
154164
/// Creates a new test environment with a custom SSH user
155165
///
156166
/// This method only performs basic construction without side effects.
@@ -171,7 +181,7 @@ impl TestEnvironment {
171181
/// - Temporary directory creation fails
172182
/// - SSH key setup fails
173183
/// - Templates directory is invalid
174-
pub fn with_ssh_user(
184+
fn with_ssh_user(
175185
keep_env: bool,
176186
templates_dir: impl Into<std::path::PathBuf>,
177187
ssh_user: &str,
@@ -210,48 +220,12 @@ impl TestEnvironment {
210220
///
211221
/// Returns an error if:
212222
/// - Template preparation fails
213-
pub fn init(&self) -> Result<(), TestEnvironmentError> {
223+
fn init(&self) -> Result<(), TestEnvironmentError> {
214224
Self::prepare_environment(&self.services)?;
215225
self.log_environment_info();
216226
Ok(())
217227
}
218228

219-
/// Creates and initializes a new test environment with custom SSH user in one step
220-
///
221-
/// This is a convenience method that combines `with_ssh_user()` and `init()`.
222-
/// Use this when you want the full setup in one call.
223-
///
224-
/// # Arguments
225-
///
226-
/// * `keep_env` - Whether to keep the environment after tests complete
227-
/// * `templates_dir` - Path to the templates directory
228-
/// * `ssh_user` - SSH username to use for connections
229-
/// * `instance_name` - Name for the instance to be deployed
230-
/// * `environment_type` - The type of test environment (Container or `VirtualMachine`)
231-
///
232-
/// # Errors
233-
///
234-
/// Returns an error if:
235-
/// - Construction fails (see `with_ssh_user()` for details)
236-
/// - Initialization fails (see `init()` for details)
237-
pub fn with_ssh_user_and_init(
238-
keep_env: bool,
239-
templates_dir: impl Into<std::path::PathBuf>,
240-
ssh_user: &str,
241-
instance_name: InstanceName,
242-
environment_type: TestEnvironmentType,
243-
) -> Result<Self, TestEnvironmentError> {
244-
let env = Self::with_ssh_user(
245-
keep_env,
246-
templates_dir,
247-
ssh_user,
248-
instance_name,
249-
environment_type,
250-
)?;
251-
env.init()?;
252-
Ok(env)
253-
}
254-
255229
/// Validates input parameters
256230
fn validate_inputs(templates_dir: &std::path::Path) -> Result<(), TestEnvironmentError> {
257231
if templates_dir.as_os_str().is_empty() {

0 commit comments

Comments
 (0)