Skip to main content

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

1//! Warning message type for non-critical issues
2
3use super::super::{Channel, OutputMessage, Theme, VerbosityLevel};
4
5/// Warning message for non-critical issues
6///
7/// Warning messages alert users to potential issues that don't prevent
8/// operation completion but may need attention.
9pub struct WarningMessage {
10    /// The warning message text
11    pub text: String,
12}
13
14impl OutputMessage for WarningMessage {
15    fn format(&self, theme: &Theme) -> String {
16        format!("{}  {}\n", theme.warning_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        "WarningMessage"
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn it_should_include_extra_space_when_formatting_warning() {
38        let theme = Theme::emoji();
39        let message = WarningMessage {
40            text: "Warning text".to_string(),
41        };
42
43        let formatted = message.format(&theme);
44
45        // Warning messages include two spaces after the symbol
46        assert_eq!(formatted, "⚠️  Warning text\n");
47    }
48
49    #[test]
50    fn it_should_require_normal_verbosity_when_displaying_warning() {
51        let message = WarningMessage {
52            text: "Warning text".to_string(),
53        };
54
55        assert_eq!(message.required_verbosity(), VerbosityLevel::Normal);
56    }
57
58    #[test]
59    fn it_should_use_stderr_channel_when_displaying_warning() {
60        let message = WarningMessage {
61            text: "Warning text".to_string(),
62        };
63
64        assert_eq!(message.channel(), Channel::Stderr);
65    }
66}