v0.1.3-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-logging-lib/unit_tests/runtime.rs
|
||||
// version: 6
|
||||
// version: 8
|
||||
|
||||
#[test]
|
||||
fn level_mapping_covers_all_ksp_levels() {
|
||||
@@ -56,7 +56,7 @@ fn disabled_runtime_has_no_layers_or_outputs() {
|
||||
};
|
||||
assert!(prepared.layers.is_empty());
|
||||
assert!(prepared.outputs.console.is_none());
|
||||
assert!(prepared.outputs.file.is_none());
|
||||
assert!(prepared.outputs.files.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,7 +75,7 @@ fn console_runtime_composes_takeover_filter_before_formatter_and_owns_guard() {
|
||||
};
|
||||
assert_eq!(prepared.layers.len(), 1);
|
||||
assert!(prepared.outputs.console.is_some());
|
||||
assert!(prepared.outputs.file.is_none());
|
||||
assert!(prepared.outputs.files.is_empty());
|
||||
assert_eq!(prepared.outputs.dropped_lines(), crate::DroppedLines::zero());
|
||||
}
|
||||
|
||||
@@ -103,40 +103,74 @@ fn takeover_filter_prefers_more_specific_ksp_prefixes_and_supports_off() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_multi_sink_runtime_rejects_new_capabilities_instead_of_ignoring_them() {
|
||||
let routed_console = crate::ConsoleSettings::new(
|
||||
fn multi_sink_runtime_accepts_metadata_routing_formats_and_console_ansi() {
|
||||
let root = std::env::temp_dir().join(format!("ksp-pre005-unit-{}", std::process::id()));
|
||||
let _cleanup_before = std::fs::remove_dir_all(root.as_path());
|
||||
let console = crate::ConsoleSettings::new(
|
||||
true,
|
||||
crate::ConsoleOutput::Stdout,
|
||||
true,
|
||||
crate::LogFormat::Compact,
|
||||
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["ksp-logging-lib".to_string()], std::vec!["logging".to_string()]),
|
||||
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["ksp-logging-lib".to_string()], std::vec!["*".to_string()]),
|
||||
);
|
||||
let routed_settings =
|
||||
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::Some(routed_console), std::vec::Vec::new());
|
||||
assert!(routed_settings.validate().is_ok());
|
||||
assert!(super::prepare_runtime(&routed_settings).is_err());
|
||||
let first_file = crate::FileSettings::new(
|
||||
"file.first",
|
||||
true,
|
||||
"logs",
|
||||
root.join("first"),
|
||||
"first.log",
|
||||
crate::FileRotation::Never,
|
||||
crate::LogFormat::Human,
|
||||
crate::OutputFilter::unrestricted(),
|
||||
crate::LogFormat::Pretty,
|
||||
crate::OutputFilter::new(crate::LogFilterLevel::Info, std::vec!["ksp-logging-lib".to_string()], std::vec!["*".to_string()]),
|
||||
);
|
||||
let second_file = crate::FileSettings::new(
|
||||
"file.second",
|
||||
true,
|
||||
"logs",
|
||||
"second.log",
|
||||
root.join("second"),
|
||||
"second.jsonl",
|
||||
crate::FileRotation::Never,
|
||||
crate::LogFormat::Human,
|
||||
crate::OutputFilter::unrestricted(),
|
||||
crate::LogFormat::Json,
|
||||
crate::OutputFilter::new(crate::LogFilterLevel::Error, std::vec!["*".to_string()], std::vec!["*".to_string()]),
|
||||
);
|
||||
let multi_file_settings =
|
||||
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![first_file, second_file]);
|
||||
assert!(multi_file_settings.validate().is_ok());
|
||||
assert!(super::prepare_runtime(&multi_file_settings).is_err());
|
||||
let settings = crate::LoggingSettings::new(
|
||||
crate::LogFilterLevel::Trace,
|
||||
crate::SpanEvents::Off,
|
||||
std::option::Option::Some(console),
|
||||
std::vec![first_file, second_file],
|
||||
);
|
||||
let result = super::prepare_runtime(&settings);
|
||||
assert!(result.is_ok());
|
||||
let prepared = match result {
|
||||
std::result::Result::Ok(prepared) => prepared,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert_eq!(prepared.layers.len(), 1);
|
||||
assert!(prepared.outputs.console.is_some());
|
||||
assert_eq!(prepared.outputs.files.len(), 2);
|
||||
assert_eq!(prepared.outputs.file_dropped_lines("file.first"), std::option::Option::Some(0));
|
||||
assert_eq!(prepared.outputs.file_dropped_lines("file.second"), std::option::Option::Some(0));
|
||||
drop(prepared);
|
||||
let cleanup_after = std::fs::remove_dir_all(root.as_path());
|
||||
assert!(cleanup_after.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn domain_routing_is_explicitly_deferred_instead_of_ignored() {
|
||||
let console = crate::ConsoleSettings::new(
|
||||
true,
|
||||
crate::ConsoleOutput::Stdout,
|
||||
false,
|
||||
crate::LogFormat::Human,
|
||||
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["*".to_string()], std::vec!["logging".to_string()]),
|
||||
);
|
||||
let settings = crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::Some(console), std::vec::Vec::new());
|
||||
assert!(settings.validate().is_ok());
|
||||
let result = super::prepare_runtime(&settings);
|
||||
assert!(result.is_err());
|
||||
let error = match result {
|
||||
std::result::Result::Ok(_) => return,
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_SETTINGS);
|
||||
}
|
||||
|
||||
struct BlockingWriter {
|
||||
|
||||
Reference in New Issue
Block a user