-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
95 lines (78 loc) · 3.46 KB
/
Copy pathmod.rs
File metadata and controls
95 lines (78 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Integration tests for configure command presentation layer
//!
//! These tests verify the complete workflow of the configure command
//! from CLI interface to application layer integration.
#[cfg(test)]
mod integration_tests {
use std::cell::RefCell;
use std::sync::Arc;
use parking_lot::ReentrantMutex;
use crate::domain::environment::repository::EnvironmentRepository;
use crate::infrastructure::persistence::repository_factory::RepositoryFactory;
use crate::presentation::controllers::configure;
use crate::presentation::controllers::configure::handler::ConfigureCommandController;
use crate::presentation::controllers::constants::DEFAULT_LOCK_TIMEOUT;
use crate::presentation::views::testing::TestUserOutput;
use crate::presentation::views::{UserOutput, VerbosityLevel};
use crate::shared::clock::Clock;
use crate::shared::SystemClock;
/// Create test dependencies for configure command integration tests
#[allow(clippy::type_complexity)]
fn create_test_dependencies(
temp_dir: &tempfile::TempDir,
) -> (
Arc<ReentrantMutex<RefCell<UserOutput>>>,
Arc<dyn EnvironmentRepository + Send + Sync>,
Arc<dyn Clock>,
) {
let (user_output, _, _) =
TestUserOutput::new(VerbosityLevel::Normal).into_reentrant_wrapped();
let data_dir = temp_dir.path().join("data");
let repository_factory = RepositoryFactory::new(DEFAULT_LOCK_TIMEOUT);
let repository = repository_factory.create(data_dir);
let clock = Arc::new(SystemClock);
(user_output, repository, clock)
}
#[tokio::test]
async fn configure_command_validates_environment_name() {
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = ConfigureCommandController::new(repository, clock, user_output.clone())
.execute("invalid_name_with_underscore");
assert!(result.is_err());
let error = result.unwrap_err();
assert!(matches!(
error,
configure::ConfigureSubcommandError::InvalidEnvironmentName { .. }
));
}
#[tokio::test]
async fn configure_command_provides_help_for_invalid_name() {
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = ConfigureCommandController::new(repository, clock, user_output.clone())
.execute("bad_name");
assert!(result.is_err());
let error = result.unwrap_err();
let help = error.help();
assert!(help.contains("Invalid Environment Name"));
assert!(help.contains("1-63 characters"));
}
#[tokio::test]
async fn configure_command_propagates_repository_errors() {
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = ConfigureCommandController::new(repository, clock, user_output.clone())
.execute("nonexistent-environment");
assert!(result.is_err());
// Repository will return NotFound error, wrapped in ConfigureOperationFailed
let error = result.unwrap_err();
assert!(matches!(
error,
configure::ConfigureSubcommandError::ConfigureOperationFailed { .. }
));
}
}