Skip to content

Commit ffee332

Browse files
committed
docs: add resource management rules to testing conventions
- Add clear guidelines for test resource cleanup and isolation - Include rules about tests cleaning up after themselves - Add warning against interfering with production data directories - Provide practical examples showing good vs bad practices - Document use of temporary directories for test isolation
1 parent 4aade9a commit ffee332

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/contributing/testing.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,51 @@ fn test_serialization() { /* ... */ }
5858
- **BDD Style**: Follows Behavior-Driven Development naming conventions
5959
- **Maintainability**: Easier to understand test failures and purpose
6060

61+
## 🧹 Resource Management
62+
63+
Tests should be isolated and clean up after themselves to avoid interfering with production data or leaving artifacts behind.
64+
65+
### Key Rules
66+
67+
- **Tests should clean the resources they create** - Use temporary directories or clean up generated files
68+
- **They should not interfere with production data** - Never use real application directories like `./data` or `./build` in tests
69+
70+
### Example
71+
72+
#### ✅ Good: Using Temporary Directories
73+
74+
```rust
75+
use tempfile::TempDir;
76+
77+
#[test]
78+
fn it_should_create_environment_with_auto_generated_paths() {
79+
// Use temporary directory to avoid creating real directories
80+
let temp_dir = TempDir::new().unwrap();
81+
let temp_path = temp_dir.path();
82+
83+
let env_name = EnvironmentName::new("test-example".to_string()).unwrap();
84+
let ssh_credentials = create_test_ssh_credentials(&temp_path);
85+
let environment = Environment::new(env_name, ssh_credentials);
86+
87+
assert!(environment.data_dir().starts_with(temp_path));
88+
assert!(environment.build_dir().starts_with(temp_path));
89+
90+
// TempDir automatically cleans up when dropped
91+
}
92+
```
93+
94+
#### ❌ Avoid: Creating Real Directories
95+
96+
```rust
97+
#[test]
98+
fn it_should_create_environment() {
99+
// Don't do this - creates real directories that persist after tests
100+
let env_name = EnvironmentName::new("test".to_string()).unwrap();
101+
let environment = Environment::new(env_name, ssh_credentials);
102+
// Creates ./data/test and ./build/test directories
103+
}
104+
```
105+
61106
## 🚀 Getting Started
62107

63108
When writing new tests, always use the `it_should_` prefix and describe the specific behavior being validated. This makes the test suite more readable and maintainable for all contributors.

0 commit comments

Comments
 (0)