Skip to content

Commit

Permalink
add Telemetry read from csv & generate json test
Browse files Browse the repository at this point in the history
  • Loading branch information
sksat committed Dec 5, 2024
1 parent 7cd09b7 commit af01cba
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tlmcmddb-csv/src/tlm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,56 @@ pub fn parse_csv<R: Read>(telemetry_name: String, rdr: R) -> Result<tlmcmddb::tl
let mut iter = csv.records();
telemetry::parse(telemetry_name, &mut iter)
}

#[cfg(test)]
mod tests {
use super::*;

use std::io::Cursor;

fn parse_testdata() -> Result<tlmcmddb::tlm::Telemetry> {
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)
}
}

0 comments on commit af01cba

Please sign in to comment.