-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtests.rs
More file actions
129 lines (107 loc) · 4.26 KB
/
Copy pathtests.rs
File metadata and controls
129 lines (107 loc) · 4.26 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! Tests for the Run Command Controller
//!
//! This module contains integration tests for the run command controller,
//! testing error handling and workflow execution.
use std::cell::RefCell;
use std::sync::Arc;
use parking_lot::ReentrantMutex;
use tempfile::TempDir;
use crate::domain::environment::repository::EnvironmentRepository;
use crate::infrastructure::persistence::repository_factory::RepositoryFactory;
use crate::presentation::controllers::constants::DEFAULT_LOCK_TIMEOUT;
use crate::presentation::controllers::run::handler::RunCommandController;
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 run command handler tests
#[allow(clippy::type_complexity)]
fn create_test_dependencies(
temp_dir: &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)
}
mod environment_name_validation {
use super::*;
use crate::presentation::controllers::run::errors::RunSubcommandError;
#[tokio::test]
async fn it_should_reject_names_with_underscores() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = RunCommandController::new(repository, clock, user_output)
.execute("invalid_name")
.await;
assert!(matches!(
result,
Err(RunSubcommandError::InvalidEnvironmentName { .. })
));
}
#[tokio::test]
async fn it_should_reject_empty_names() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = RunCommandController::new(repository, clock, user_output)
.execute("")
.await;
assert!(matches!(
result,
Err(RunSubcommandError::InvalidEnvironmentName { .. })
));
}
#[tokio::test]
async fn it_should_reject_names_starting_with_hyphen() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = RunCommandController::new(repository, clock, user_output)
.execute("-invalid")
.await;
assert!(matches!(
result,
Err(RunSubcommandError::InvalidEnvironmentName { .. })
));
}
}
mod real_workflow {
use super::*;
use crate::presentation::controllers::run::errors::RunSubcommandError;
#[tokio::test]
async fn it_should_return_not_accessible_when_environment_does_not_exist() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
// Valid environment name but environment doesn't exist
let result = RunCommandController::new(repository, clock, user_output)
.execute("production")
.await;
assert!(
matches!(
result,
Err(RunSubcommandError::EnvironmentNotAccessible { .. })
),
"Should fail with EnvironmentNotAccessible for non-existent environment"
);
}
#[tokio::test]
async fn it_should_return_not_accessible_for_hyphenated_names_when_env_does_not_exist() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = RunCommandController::new(repository, clock, user_output)
.execute("my-test-env")
.await;
assert!(
matches!(
result,
Err(RunSubcommandError::EnvironmentNotAccessible { .. })
),
"Should fail with EnvironmentNotAccessible for non-existent environment"
);
}
}