Skip to content

Commit

Permalink
test: add a few more tests in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bconn98 committed Feb 24, 2024
1 parent 4a34bce commit 1d282b4
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/config/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,12 @@ pub enum ConfigError {

#[cfg(test)]
mod test {
use super::*;
use crate::{append::console::ConsoleAppender, filter::threshold::ThresholdFilter};
use log::LevelFilter;

#[test]
fn check_logger_name() {
fn test_check_logger_name() {
let tests = [
("", false),
("asdf", true),
Expand All @@ -488,4 +492,50 @@ mod test {
);
}
}

#[test]
fn test_appender_simple() {
let stdout = ConsoleAppender::builder().build();
let appender = Appender::builder().build("stdout", Box::new(stdout));

assert_eq!(appender.name(), "stdout");
assert!(appender.filters().is_empty());

// Nothing to test on this right now
let _appender = appender.appender();
}

#[test]
fn test_appender_filter() {
let stdout = ConsoleAppender::builder().build();

let filter = ThresholdFilter::new(LevelFilter::Warn);

let appender = Appender::builder()
.filter(Box::new(filter))
.build("stdout", Box::new(stdout));

assert_eq!(appender.name(), "stdout");
assert!(!appender.filters().is_empty());
assert_eq!(appender.filters().len(), 1);

// Nothing to test on this right now
let _appender = appender.appender();
}

#[test]
fn test_simple_root() {
let mut root = Root::builder().build(LevelFilter::Debug);

// Test level set by builder and is accessible
assert_eq!(LevelFilter::Debug, root.level());

// Test no appenders added to builder
assert!(root.appenders().is_empty());

// Test level set after root created and is accessible
root.set_level(LevelFilter::Warn);
assert_ne!(LevelFilter::Debug, root.level());
assert_eq!(LevelFilter::Warn, root.level());
}
}

0 comments on commit 1d282b4

Please sign in to comment.