-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtests.rs
More file actions
132 lines (110 loc) · 4.7 KB
/
tests.rs
File metadata and controls
132 lines (110 loc) · 4.7 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
130
131
132
//! Tests for the Release Command Controller
//!
//! This module contains integration tests for the release 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::file_repository_factory::FileRepositoryFactory;
use crate::presentation::cli::controllers::constants::DEFAULT_LOCK_TIMEOUT;
use crate::presentation::cli::controllers::release::handler::ReleaseCommandController;
use crate::presentation::cli::input::cli::OutputFormat;
use crate::presentation::cli::views::testing::TestUserOutput;
use crate::presentation::cli::views::{UserOutput, VerbosityLevel};
use crate::shared::clock::Clock;
use crate::shared::SystemClock;
/// Create test dependencies for release 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 file_repository_factory = FileRepositoryFactory::new(DEFAULT_LOCK_TIMEOUT);
let repository = file_repository_factory.create(data_dir);
let clock = Arc::new(SystemClock);
(user_output, repository, clock)
}
mod environment_name_validation {
use super::*;
use crate::presentation::cli::controllers::release::errors::ReleaseSubcommandError;
#[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 = ReleaseCommandController::new(repository, clock, user_output)
.execute("invalid_name", OutputFormat::Text)
.await;
assert!(matches!(
result,
Err(ReleaseSubcommandError::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 = ReleaseCommandController::new(repository, clock, user_output)
.execute("", OutputFormat::Text)
.await;
assert!(matches!(
result,
Err(ReleaseSubcommandError::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 = ReleaseCommandController::new(repository, clock, user_output)
.execute("-invalid", OutputFormat::Text)
.await;
assert!(matches!(
result,
Err(ReleaseSubcommandError::InvalidEnvironmentName { .. })
));
}
}
mod workflow_errors {
use super::*;
use crate::presentation::cli::controllers::release::errors::ReleaseSubcommandError;
#[tokio::test]
async fn it_should_return_application_layer_error_for_nonexistent_environment() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
// Valid name but environment doesn't exist
let result = ReleaseCommandController::new(repository, clock, user_output)
.execute("production", OutputFormat::Text)
.await;
// Should fail with ApplicationLayerError because environment doesn't exist
assert!(
matches!(
result,
Err(ReleaseSubcommandError::ApplicationLayerError { .. })
),
"Should fail with ApplicationLayerError when environment doesn't exist"
);
}
#[tokio::test]
async fn it_should_return_application_layer_error_for_hyphenated_nonexistent_environment() {
let temp_dir = TempDir::new().unwrap();
let (user_output, repository, clock) = create_test_dependencies(&temp_dir);
let result = ReleaseCommandController::new(repository, clock, user_output)
.execute("my-test-env", OutputFormat::Text)
.await;
// Should fail with ApplicationLayerError because environment doesn't exist
assert!(
matches!(
result,
Err(ReleaseSubcommandError::ApplicationLayerError { .. })
),
"Should fail with ApplicationLayerError when hyphenated environment doesn't exist"
);
}
}