src/handlers/mock_handler.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source |
|---|---|---|
| 1 | // | |
| 2 | // File Name: mock_handler.rs | |
| 3 | // Project Name: flogging | |
| 4 | // | |
| 5 | // Copyright (C) 2025 Bradley Willcott | |
| 6 | // | |
| 7 | // SPDX-License-Identifier: GPL-3.0-or-later | |
| 8 | // | |
| 9 | // This library (crate) is free software: you can redistribute it and/or modify | |
| 10 | // it under the terms of the GNU General Public License as published by | |
| 11 | // the Free Software Foundation, either version 3 of the License, or | |
| 12 | // (at your option) any later version. | |
| 13 | // | |
| 14 | // This library (crate) is distributed in the hope that it will be useful, | |
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | // GNU General Public License for more details. | |
| 18 | // | |
| 19 | // You should have received a copy of the GNU General Public License | |
| 20 | // along with this library (crate). If not, see <https://www.gnu.org/licenses/>. | |
| 21 | // | |
| 22 | ||
| 23 | //! | |
| 24 | //! # Mock Handler | |
| 25 | //! | |
| 26 | //! Returned as Default for Custom handler that is missing. | |
| 27 | //! | |
| 28 | ||
| 29 | use crate::*; | |
| 30 | use ::{ | |
| 31 | , | |
| 32 | ::{self,}, | |
| 33 | }; | |
| 34 | ||
| 35 | /// | |
| 36 | /// This is used as a _fake_ or _mock_ handler. | |
| 37 | /// | |
| 38 | /// It is a filler for `Handler::Custom(label).create()`. It is also used | |
| 39 | /// in examples for custom handlers. | |
| 40 | /// | |
| 41 | #[derive(,)] | |
| 42 | pub struct MockHandler {} | |
| 43 | ||
| 44 | impl ::for MockHandler { | |
| 45 | 1 | fn fmt(&selff: &mut ::<_>) -> :: { |
| 46 | 1 | write!( "MockHandler!!") |
| 47 | 1 | } |
| 48 | } | |
| 49 | ||
| 50 | impl for MockHandler { | |
| 51 | 1 | fn create(_name: &str) -> <Self> |
| 52 | 1 | where |
| 53 | 1 | Self: |
| 54 | { | |
| 55 | 1 | Ok(Default::()) |
| 56 | 1 | } |
| 57 | ||
| 58 | /// | |
| 59 | /// This is a 'NoOp' fn. | |
| 60 | /// | |
| 61 | 1 | fn close(&mut self) {} |
| 62 | ||
| 63 | /// | |
| 64 | /// This is a 'NoOp' fn. | |
| 65 | /// | |
| 66 | 1 | fn flush(&mut self) {} |
| 67 | ||
| 68 | 1 | fn get_formatter(&self) -> { |
| 69 | 1 | Default::() |
| 70 | 1 | } |
| 71 | ||
| 72 | 2 | fn get_log(&self) -> { |
| 73 | 2 | Default::() |
| 74 | 2 | } |
| 75 | ||
| 76 | /// | |
| 77 | /// This is always `false`. | |
| 78 | /// | |
| 79 | 1 | fn is_open(&self) -> bool { |
| 80 | 1 | false |
| 81 | 1 | } |
| 82 | ||
| 83 | #[allow()] | |
| 84 | 2 | fn publish(&mut self_log_entry: &) {} |
| 85 | ||
| 86 | 1 | fn set_formatter(&mut self_formatter:) {} |
| 87 | ||
| 88 | /// | |
| 89 | /// This is a 'NoOp' fn. | |
| 90 | /// | |
| 91 | 1 | fn set_test_mode(&mut self_state: bool) {} |
| 92 | } | |
| 93 | ||
| 94 | #[cfg()] | |
| 95 | mod tests { | |
| 96 | use super::*; | |
| 97 | ||
| 98 | use crate::{,,}; | |
| 99 | ||
| 100 | #[test] | |
| 101 | 1 | fn handler_trait() { |
| 102 | 1 | let mut= ::( |
| 103 | 1 | module_path!(), |
| 104 | 1 | "Mock", |
| 105 | 1 | Box::(::(module_path!())unwrap()), |
| 106 | ); | |
| 107 | ||
| 108 | // println!("{log}"); | |
| 109 | 1 | assert_eq!("flogging::handlers::mock_handler::tests:: - [INFO]\n\nHandler::Custom(Mock): MockHandler!!\n\n"to_string(),to_string()); |
| 110 | 1 | info("trait methods"); |
| 111 | 1 | warning("The sky is falling!"); |
| 112 | ||
| 113 | 1 | let= |
| 114 | 1 | get_handler(crate::::("Mock"to_string())) |
| 115 | 1 | unwrap(); |
| 116 | ||
| 117 | 1 | set_test_mode(true); |
| 118 | ||
| 119 | 1 | assert!(!is_open()); |
| 120 | ||
| 121 | 1 | set_formatter(::create(None)); |
| 122 | ||
| 123 | 1 | assert_eq!( |
| 124 | 1 | get_formatter()to_string(), |
| 125 | 1 | "dt_fmt: \"\" - fmt_string: \"{mod_path}->{fn_name} [{level:7}] {message}\"" |
| 126 | 1 | to_string() |
| 127 | ); | |
| 128 | ||
| 129 | 1 | assert_eq!(get_log(), ""to_string()); |
| 130 | ||
| 131 | 1 | flush(); |
| 132 | 1 | assert_eq!(get_log(), ""to_string()); |
| 133 | 1 | close(); |
| 134 | 1 | } |
| 135 | } |