mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
test fix
This commit is contained in:
parent
0def1f07ef
commit
7f575659a5
2 changed files with 27 additions and 22 deletions
|
|
@ -17,7 +17,7 @@ pub const TIME_FORMAT: EncodedConfig = Config::DEFAULT
|
||||||
})
|
})
|
||||||
.encode();
|
.encode();
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct LogLine<'a> {
|
pub struct LogLine<'a> {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
|
|
@ -151,7 +151,7 @@ impl<'a> LogLine<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Hash)]
|
#[derive(Deserialize, Debug, Hash, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct Exception<'a> {
|
pub struct Exception<'a> {
|
||||||
pub message: Cow<'a, str>,
|
pub message: Cow<'a, str>,
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,9 @@ impl<'a> SingleMatchState<'a> {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_matcher() {
|
fn test_matcher() {
|
||||||
use crate::logline::Exception;
|
use crate::logline::Exception;
|
||||||
|
use std::str::FromStr;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
use tinystr::TinyAsciiStr;
|
||||||
|
|
||||||
const STATEMENTS: &[LoggingStatement] = &[
|
const STATEMENTS: &[LoggingStatement] = &[
|
||||||
LoggingStatement {
|
LoggingStatement {
|
||||||
|
|
@ -322,6 +324,22 @@ fn test_matcher() {
|
||||||
has_meaningful_message: true,
|
has_meaningful_message: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let default_log = LogLine {
|
||||||
|
version: "29",
|
||||||
|
app: "core".into(),
|
||||||
|
level: LogLevel::Error,
|
||||||
|
message: "Not allowed to rename a shared album".into(),
|
||||||
|
exception: None,
|
||||||
|
time: OffsetDateTime::now_utc(),
|
||||||
|
index: 0,
|
||||||
|
method: TinyAsciiStr::from_str("GET").unwrap(),
|
||||||
|
remote: TinyAsciiStr::from_str("1.2.3.4").unwrap(),
|
||||||
|
user: TinyAsciiStr::from_str("user").unwrap(),
|
||||||
|
url: "/url".into(),
|
||||||
|
request_id: TinyAsciiStr::from_str("123456").unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
let matcher = Matcher::new(&StatementList::new(vec![("", STATEMENTS)]));
|
let matcher = Matcher::new(&StatementList::new(vec![("", STATEMENTS)]));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some(MatchResult::Single(0)),
|
Some(MatchResult::Single(0)),
|
||||||
|
|
@ -330,9 +348,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Error,
|
level: LogLevel::Error,
|
||||||
message: "Not allowed to rename a shared album".into(),
|
message: "Not allowed to rename a shared album".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -342,9 +358,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Error,
|
level: LogLevel::Error,
|
||||||
message: "Not allowed to rename an album".into(),
|
message: "Not allowed to rename an album".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -354,9 +368,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Error,
|
level: LogLevel::Error,
|
||||||
message: "You are not allowed to edit link shares that you don't own".into(),
|
message: "You are not allowed to edit link shares that you don't own".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -366,9 +378,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Info,
|
level: LogLevel::Info,
|
||||||
message: "You are not allowed to edit link shares that you don't own".into(),
|
message: "You are not allowed to edit link shares that you don't own".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -379,9 +389,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Error,
|
level: LogLevel::Error,
|
||||||
message: "Unsupported query value for mimetype: %/text, only values in the format \"mime/type\" or \"mime/%\" are supported".into(),
|
message: "Unsupported query value for mimetype: %/text, only values in the format \"mime/type\" or \"mime/%\" are supported".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -399,8 +407,7 @@ fn test_matcher() {
|
||||||
file: "short".into(),
|
file: "short".into(),
|
||||||
line: 68,
|
line: 68,
|
||||||
}),
|
}),
|
||||||
time: OffsetDateTime::now_utc(),
|
..default_log.clone()
|
||||||
index: 0,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -411,9 +418,7 @@ fn test_matcher() {
|
||||||
app: "core".into(),
|
app: "core".into(),
|
||||||
level: LogLevel::Error,
|
level: LogLevel::Error,
|
||||||
message: "Not allowed to rename 'foo to' to to2".into(),
|
message: "Not allowed to rename 'foo to' to to2".into(),
|
||||||
exception: None,
|
..default_log.clone()
|
||||||
time: OffsetDateTime::now_utc(),
|
|
||||||
index: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue