Skip to content

Commit

Permalink
tests(pact_ffi): Add tests for log_level_from_c_char
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Jan 25, 2024
1 parent bbf61ba commit b82f0a4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion rust/pact_ffi/src/lib.rs
Expand Up @@ -338,7 +338,7 @@ mod tests {
use expectest::prelude::*;
use rstest::rstest;

use super::log_level_filter_from_c_char;
use super::*;
use tracing_core::LevelFilter;

#[rstest]
Expand All @@ -362,4 +362,26 @@ mod tests {
let result = unsafe { log_level_filter_from_c_char(value.as_ptr()) };
expect!(result).to(be_equal_to(level));
}

#[rstest]
#[case("trace", Level::TRACE)]
#[case("TRACE", Level::TRACE)]
#[case("debug", Level::DEBUG)]
#[case("DEBUG", Level::DEBUG)]
#[case("info", Level::INFO)]
#[case("INFO", Level::INFO)]
#[case("warn", Level::WARN)]
#[case("WARN", Level::WARN)]
#[case("error", Level::ERROR)]
#[case("ERROR", Level::ERROR)]
#[case("off", Level::INFO)]
#[case("OFF", Level::INFO)]
#[case("none", Level::INFO)]
#[case("NONE", Level::INFO)]
#[case("invalid", Level::INFO)]
fn log_level_from_c_char_test(#[case] text: String, #[case] level: Level) {
let value = CString::new(text).unwrap();
let result = unsafe { log_level_from_c_char(value.as_ptr()) };
expect!(result).to(be_equal_to(level));
}
}

0 comments on commit b82f0a4

Please sign in to comment.