Skip to main content

torrust_tracker_deployer_lib/presentation/cli/views/messages/
success.rs

1//! Success message type for completed operations
2
3use super::super::{Channel, OutputMessage, Theme, VerbosityLevel};
4
5/// Success message for completed operations
6///
7/// Success messages indicate that an operation completed successfully.
8/// They provide positive feedback to users.
9pub struct SuccessMessage {
10    /// The success message text
11    pub text: String,
12}
13
14impl OutputMessage for SuccessMessage {
15    fn format(&self, theme: &Theme) -> String {
16        format!("{} {}\n", theme.success_symbol(), self.text)
17    }
18
19    fn required_verbosity(&self) -> VerbosityLevel {
20        VerbosityLevel::Normal
21    }
22
23    fn channel(&self) -> Channel {
24        Channel::Stderr
25    }
26
27    fn type_name(&self) -> &'static str {
28        "SuccessMessage"
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn it_should_format_with_theme_when_displaying_success() {
38        let theme = Theme::plain();
39        let message = SuccessMessage {
40            text: "Operation complete".to_string(),
41        };
42
43        let formatted = message.format(&theme);
44
45        assert_eq!(formatted, "[OK] Operation complete\n");
46    }
47
48    #[test]
49    fn it_should_require_normal_verbosity_when_displaying_success() {
50        let message = SuccessMessage {
51            text: "Operation complete".to_string(),
52        };
53
54        assert_eq!(message.required_verbosity(), VerbosityLevel::Normal);
55    }
56
57    #[test]
58    fn it_should_use_stderr_channel_when_displaying_success() {
59        let message = SuccessMessage {
60            text: "Operation complete".to_string(),
61        };
62
63        assert_eq!(message.channel(), Channel::Stderr);
64    }
65}