test(journaldriver): Add test for serialising timestamps

Change-Id: I5b769f5974546fd4f4f853111bd17c9d22d73a5e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5310
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-02-18 12:31:46 +03:00 committed by clbot
parent 19a13e08a8
commit af512558e6

View file

@ -21,6 +21,28 @@ fn test_text_entry_serialization() {
)
}
#[test]
fn test_timestamped_entry_serialization() {
let timestamp: DateTime<Utc> = "1952-10-07T12:00:00Z".to_string().parse().unwrap();
let entry = LogEntry {
labels: Value::Null,
timestamp: Some(timestamp),
payload: Payload::TextPayload {
text_payload: "test entry".into(),
},
severity: None,
};
let expected =
"{\"labels\":null,\"timestamp\":\"1952-10-07T12:00:00Z\",\"textPayload\":\"test entry\"}";
let result = to_string(&entry).expect("serialization failed");
assert_eq!(
expected, result,
"Plain text payload should serialize correctly"
)
}
#[test]
fn test_json_entry_serialization() {
let entry = LogEntry {
@ -37,7 +59,7 @@ fn test_json_entry_serialization() {
let expected = "{\"labels\":null,\"jsonPayload\":{\"message\":\"JSON test\"}}";
let result = to_string(&entry).expect("serialization failed");
assert_eq!(expected, result, "JSOn payload should serialize correctly")
assert_eq!(expected, result, "JSON payload should serialize correctly")
}
#[test]