From af512558e695605fdfc1b3ede407a6067e355e30 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 18 Feb 2022 12:31:46 +0300 Subject: test(journaldriver): Add test for serialising timestamps Change-Id: I5b769f5974546fd4f4f853111bd17c9d22d73a5e Reviewed-on: https://cl.tvl.fyi/c/depot/+/5310 Tested-by: BuildkiteCI Autosubmit: tazjin Reviewed-by: sterni --- ops/journaldriver/src/tests.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ops/journaldriver/src/tests.rs b/ops/journaldriver/src/tests.rs index 8a07cc6fed9e..391d39947101 100644 --- a/ops/journaldriver/src/tests.rs +++ b/ops/journaldriver/src/tests.rs @@ -21,6 +21,28 @@ fn test_text_entry_serialization() { ) } +#[test] +fn test_timestamped_entry_serialization() { + let timestamp: DateTime = "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] -- cgit 1.4.1