Last active
June 1, 2017 01:22
-
-
Save xrl/45cbd37030bbafa7b93f485e19e8d41c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Users/xlange/.cargo/bin/cargo test --color=always -- --nocapture | |
Compiling whaletail v0.1.0 (file:///Users/xlange/IdeaProjects/whale-tail) | |
warning: unused import: `test::Bencher` | |
--> src/lib.rs:22:9 | |
| | |
22 | use test::Bencher; | |
| ^^^^^^^^^^^^^ | |
| | |
= note: #[warn(unused_imports)] on by default | |
Finished dev [unoptimized + debuginfo] target(s) in 1.46 secs | |
Running target/debug/deps/whaletail-f5fadca46f2fa91d | |
running 1 test | |
"{\"log\":\"SABnzbd settings\\n\",\"stream\":\"stdout\",\"time\":\"2017-04-26T15:48:36.126328492Z\"}" | |
thread 'tests::parse_file' panicked at 'called `Result::unwrap()` on an `Err` value: ErrorImpl { code: Message("invalid type: string \"SABnzbd settings\\n\", expected a borrowed string"), line: 1, column: 27 }', src/libcore/result.rs:859 | |
stack backtrace: | |
0: 0x1001cbc43 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h34a7b169ac42b490 | |
1: 0x1001cda54 - std::panicking::default_hook::{{closure}}::hcc7f46907143dca1 | |
2: 0x1001cd66c - std::panicking::default_hook::h9cd165f254d86e53 | |
3: 0x1001cff97 - std::panicking::rust_panic_with_hook::h2bd2f0b446f0face | |
4: 0x1001cfe34 - std::panicking::begin_panic::h1732f61ecaaa434e | |
5: 0x1001cfda2 - std::panicking::begin_panic_fmt::h2948dd4668f99175 | |
6: 0x1001cfd07 - rust_begin_unwind | |
7: 0x1001f54f0 - core::panicking::panic_fmt::hb2e726f3b579b19d | |
8: 0x100159ea3 - core::result::unwrap_failed::h8af30d3fc4d97514 | |
9: 0x100156cce - <core::result::Result<T, E>>::unwrap::h68e0322a7978c96c | |
10: 0x1001604c7 - whaletail::tests::parse_file::h4936cf8b56e62286 | |
11: 0x1001715cb - <F as test::FnBox<T>>::call_box::hde864e0f2ebe212b | |
12: 0x1001d10aa - __rust_maybe_catch_panic | |
13: 0x1001640f1 - std::panicking::try::do_call::h450ec71bdec47c60 | |
14: 0x1001d10aa - __rust_maybe_catch_panic | |
15: 0x10016be74 - <F as alloc::boxed::FnBox<A>>::call_box::h70bc89ffeca4ac62 | |
16: 0x1001cd065 - std::sys::imp::thread::Thread::new::thread_start::h5852519f9f48a1f2 | |
17: 0x7fffc96e69ae - _pthread_body | |
18: 0x7fffc96e68fa - _pthread_start | |
test tests::parse_file ... FAILED | |
failures: | |
failures: | |
tests::parse_file | |
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured | |
error: test failed, to rerun pass '--lib' | |
Process finished with exit code 101 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
extern crate test; | |
extern crate serde; | |
extern crate serde_json; | |
#[macro_use] | |
extern crate serde_derive; | |
extern crate chrono; | |
use chrono::{DateTime, UTC}; | |
#[derive(Deserialize,Serialize)] | |
pub struct DockerLogLine<'a> { | |
pub log: &'a str, | |
pub stream: String, | |
pub time: DateTime<UTC> | |
} | |
#[cfg(test)] | |
mod tests { | |
use test::Bencher; | |
use super::*; | |
// #[test] | |
// fn parse_one() { | |
// let sample = r#"{ | |
// "log":"time=\"2017-05-02T15:56:35Z\" level=info msg=\"PurgeUploads starting: olderThan=2017-04-25 15:56:35.846514213 +0000 UTC, actuallyDelete=true\" \n", | |
// "stream":"stdout", | |
// "time":"2017-05-02T15:56:35.846897572Z" | |
// }"#; | |
// | |
// let _: DockerLogLine = serde_json::from_str(sample).unwrap(); | |
// } | |
// | |
// #[test] | |
// fn parse_many() { | |
// let sample = r#"{"log":"time=\"2017-05-02T15:56:35Z\" level=info msg=\"PurgeUploads starting: olderThan=2017-04-25 15:56:35.846514213 +0000 UTC, actuallyDelete=true\" \n","stream":"stdout","time":"2017-05-02T15:56:35.846897572Z"} | |
// {"log":"time=\"2017-05-02T15:56:35Z\" level=info msg=\"Purge uploads finished. Num deleted=0, num errors=0\" \n","stream":"stdout","time":"2017-05-02T15:56:35.849976968Z"} | |
// {"log":"time=\"2017-05-02T15:56:35Z\" level=info msg=\"Starting upload purge in 24h0m0s\" go.version=go1.7.3 instance.id=e930db88-e8b8-47b0-ade1-20183a3167b4 version=v2.6.0 \n","stream":"stdout","time":"2017-05-02T15:56:35.850005422Z"}"#; | |
// | |
// use std::io::{BufRead, BufReader, Cursor}; | |
// let sample_buf = BufReader::new(Cursor::new(sample)); | |
// | |
// for sample in sample_buf.lines() { | |
// let _: DockerLogLine = serde_json::from_str(&sample.unwrap()).unwrap(); | |
// } | |
// } | |
#[test] | |
fn parse_file(/* b: &mut Bencher */) { | |
use std::fs::{ File }; | |
use std::io::{ Seek, SeekFrom }; | |
let mut f = File::open("/Users/xlange/30ece7c43b7c302f43e54ac9f299ca36efb8184375eac0563c9340a15100ee3c-json.log").unwrap(); | |
// b.iter(|| { | |
{ | |
use std::io::{BufRead, BufReader}; | |
let buf_f = BufReader::new(&f); | |
for sample in buf_f.lines() { | |
let line = sample.unwrap(); | |
println!("{:?}", &line[..]); | |
let _: DockerLogLine = serde_json::from_str(&line[..]).unwrap(); | |
} | |
} | |
f.seek(SeekFrom::Start(0)).unwrap(); | |
// }) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ~/30ece7c43b7c302f43e54ac9f299ca36efb8184375eac0563c9340a15100ee3c-json.log | |
{"log":"SABnzbd settings\n","stream":"stdout","time":"2017-04-26T15:48:36.126328492Z"} | |
{"log":"================\n","stream":"stdout","time":"2017-04-26T15:48:36.12638681Z"} | |
{"log":"\n","stream":"stdout","time":"2017-04-26T15:48:36.126394484Z"} | |
{"log":" User: sabnzbd\n","stream":"stdout","time":"2017-04-26T15:48:36.12639905Z"} | |
{"log":" UID: 666\n","stream":"stdout","time":"2017-04-26T15:48:36.126403697Z"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment