From af01cba561f6851368f6faff67c48b2c520ac15c Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 5 Dec 2024 17:32:52 +0900 Subject: [PATCH] add Telemetry read from csv & generate json test --- tlmcmddb-csv/src/tlm.rs | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tlmcmddb-csv/src/tlm.rs b/tlmcmddb-csv/src/tlm.rs index 08c02eb..5448c29 100644 --- a/tlmcmddb-csv/src/tlm.rs +++ b/tlmcmddb-csv/src/tlm.rs @@ -13,3 +13,56 @@ pub fn parse_csv(telemetry_name: String, rdr: R) -> Result Result { + let csv = { + let header = include_bytes!("../fixtures/TLM_DB/valid_metadata.csv"); + let body = include_bytes!("../fixtures/TLM_DB/valid_body.csv"); + + let mut csv = header.to_vec(); + csv.extend_from_slice(body); + Cursor::new(csv) + }; + + parse_csv("".to_string(), csv) + } + + #[test] + fn test_read_csv() { + let expected: tlmcmddb::tlm::Telemetry = { + let json = include_bytes!("../fixtures/TLM_DB/valid.json"); + serde_json::from_slice(json).unwrap() + }; + + let actual = parse_testdata().unwrap(); + + assert_eq!(expected, actual) + + // make snapshot + // serde_json::to_writer_pretty( + // std::fs::OpenOptions::new() + // .create(true) + // .write(true) + // .truncate(true) + // .open("fixtures/TLM_DB/valid.json") + // .unwrap(), + // &actual, + // ); + } + + #[test] + fn test_ser_json() { + let expected = include_str!("../fixtures/TLM_DB/valid.json"); + + let tlm = parse_testdata().unwrap(); + let actual = serde_json::to_string_pretty(&tlm).unwrap(); + + assert_eq!(expected, actual) + } +}