Skip to content

Commit e7be2cc

Browse files
committed
feat: add immediate environment persistence in E2E test initialization
- Persist environment state immediately after creation in TestContext::init() - Extract persistence logic into private persist_initial_environment_state() method - Ensure Created state is saved before any commands execute - Maintain observability with proper error handling and logging This ensures environment state is captured from the beginning of tests, improving traceability and debugging capabilities for E2E test scenarios.
1 parent 1c0157a commit e7be2cc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/e2e/context.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ impl TestContext {
220220
///
221221
/// Returns an error if:
222222
/// - Template preparation fails
223+
/// - Environment persistence fails
223224
pub fn init(self) -> Result<Self, TestContextError> {
224225
Self::prepare_environment(&self.services)?;
226+
self.persist_initial_environment_state()?;
225227
self.log_environment_info();
226228
Ok(self)
227229
}
@@ -268,6 +270,28 @@ impl TestContext {
268270
Ok(())
269271
}
270272

273+
/// Persists the environment immediately after creation
274+
///
275+
/// This method ensures the environment is saved in its initial Created state
276+
/// before any commands are executed that might change the state.
277+
///
278+
/// # Errors
279+
///
280+
/// Returns an error if environment persistence fails
281+
fn persist_initial_environment_state(&self) -> Result<(), TestContextError> {
282+
let repository = self.create_repository();
283+
info!(
284+
environment = %self.environment.name(),
285+
state = %self.environment.state_name(),
286+
"Persisting initial environment state"
287+
);
288+
repository
289+
.save(&self.environment)
290+
.map_err(|e| TestContextError::ContextPreparationError {
291+
source: anyhow::anyhow!("Failed to persist initial environment state: {e}"),
292+
})
293+
}
294+
271295
/// Logs environment information
272296
fn log_environment_info(&self) {
273297
// Warn if keep_env is enabled with Container environment type

0 commit comments

Comments
 (0)