mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
Fix io capture in tests (#573)
This commit is contained in:
parent
bc31d42f22
commit
09e83a98c6
|
@ -64,9 +64,11 @@ impl fmt::Display for LogTag {
|
|||
macro_rules! lqueue {
|
||||
($audit:expr, $tag:expr, $($arg:tt)*) => ({
|
||||
use crate::audit::{LogTag, AUDIT_LINE_SIZE};
|
||||
/*
|
||||
if cfg!(test) {
|
||||
println!($($arg)*)
|
||||
}
|
||||
*/
|
||||
if ($audit.level & $tag as u32) == $tag as u32 {
|
||||
use std::fmt;
|
||||
// We have to buffer the string to over-alloc it.
|
||||
|
|
|
@ -230,7 +230,7 @@ impl<P: Processor> Layer<Registry> for TreeLayer<P> {
|
|||
|
||||
let name = attrs.metadata().name();
|
||||
let mut uuid = None;
|
||||
let mut out = TreeIo::Stderr;
|
||||
let mut out = TreeIo::Stdout;
|
||||
|
||||
attrs.record(
|
||||
&mut |field: &Field, value: &dyn fmt::Debug| match field.name() {
|
||||
|
@ -478,8 +478,26 @@ impl TreePreProcessed {
|
|||
let buf = &formatted_logs[..];
|
||||
|
||||
match processed_logs.tree_io() {
|
||||
TreeIo::Stdout => io::stdout().write_all(buf),
|
||||
TreeIo::Stderr => io::stderr().write_all(buf),
|
||||
TreeIo::Stdout => {
|
||||
// BUG - we can't write to stdout/err directly because this breaks
|
||||
// cargo test capturing of io.
|
||||
// io::stdout().write_all(buf)
|
||||
|
||||
match std::str::from_utf8(buf) {
|
||||
Ok(s) => print!("{}", s),
|
||||
Err(e) => eprintln!("CRITICAL - UNABLE TO PRINT BUFFER -> {:?}", e),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
TreeIo::Stderr => {
|
||||
// io::stderr().write_all(buf)
|
||||
|
||||
match std::str::from_utf8(buf) {
|
||||
Ok(s) => eprint!("{}", s),
|
||||
Err(e) => eprintln!("CRITICAL - UNABLE TO PRINT BUFFER -> {:?}", e),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
TreeIo::File(ref path) => OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
|
@ -493,7 +511,7 @@ impl TreePreProcessed {
|
|||
impl TreeProcessed {
|
||||
fn tree_io(self) -> TreeIo {
|
||||
match self {
|
||||
TreeProcessed::Event(_) => TreeIo::Stderr,
|
||||
TreeProcessed::Event(_) => TreeIo::Stdout,
|
||||
TreeProcessed::Span(TreeSpanProcessed { out, .. }) => out,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue