Skip to content

Commit dd0a56f

Browse files
committed
test: add simple test for file log
1 parent 5e129ec commit dd0a56f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl RingBuffer {
115115
}
116116
}
117117

118+
#[derive(Clone)]
118119
pub struct LoggerFileOptions {
119120
pub file_path: String,
120121
pub append_mode: bool,
@@ -208,3 +209,32 @@ impl Logger {
208209
}
209210
}
210211
}
212+
213+
#[cfg(test)]
214+
mod tests {
215+
use super::*;
216+
use std::fs;
217+
218+
fn setup() {
219+
fs::File::options()
220+
.read(true)
221+
.write(true)
222+
.create(true)
223+
.open("log.txt")
224+
.unwrap();
225+
}
226+
227+
#[test]
228+
fn simple_to_file() {
229+
setup();
230+
let o = LoggerFileOptions {
231+
file_path: "log.txt".to_owned(),
232+
append_mode: false,
233+
};
234+
let logger = Logger::new(1024, Some(o.clone()));
235+
logger.log_f(|| "to file".to_owned());
236+
logger.shutdown();
237+
let bytes = fs::read(o.file_path).unwrap();
238+
assert_eq!(String::from_utf8(bytes).unwrap(), "to file\n".to_owned());
239+
}
240+
}

0 commit comments

Comments
 (0)