Skip to content

Commit

Permalink
test: Adjust tests to result packaging to tar
Browse files Browse the repository at this point in the history
  • Loading branch information
zsofiak96 authored and Florian Guggi committed Jan 1, 2024
1 parent 5cc9cd3 commit 4fce424
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde = { version = "1.0.166", features = ["derive"] }
strum = { version = "0.25.0", features = ["derive"] }
serialport = "4.2.2"
test-case = "3.3.1"
tar = "0.4.40"

[dependencies.filevec]
path = "lib/filevec"
Expand Down
1 change: 0 additions & 1 deletion src/command/store_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn store_archive(
///
/// Returns Ok or passes along a file access/unzip process error
fn unpack_archive(folder: String, bytes: Vec<u8>) -> CommandResult {
// Store bytes into temporary file
// Store bytes into temporary file
let zip_path = format!("./data/{}.zip", folder);
let mut zip_file = std::fs::File::create(&zip_path)?;
Expand Down
9 changes: 7 additions & 2 deletions tests/simulation/full_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ fn full_run() {

// Check result
let result = simulate_return_result(&mut com, 1, 3).unwrap();
let mut result_archive = zip::ZipArchive::new(Cursor::new(result)).unwrap();
let mut result_archive = tar::Archive::new(Cursor::new(result));
com.send_packet(&CEPPacket::Ack).unwrap();

let result_file = result_archive.by_name(&"3").unwrap();
let result_file = result_archive
.entries()
.unwrap()
.find(|x| x.as_ref().unwrap().header().path().unwrap().ends_with("3"))
.unwrap()
.unwrap();
assert_eq!(result_file.bytes().map(|b| b.unwrap()).collect::<Vec<_>>(), vec![0xde, 0xad]);

assert_eq!(simulate_get_status(&mut com).unwrap(), [0]);
Expand Down
18 changes: 8 additions & 10 deletions tests/software_tests/return_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ fn returns_result_correctly() -> TestResult {
COBC(Data(return_result(7, 3))),
EDU(Ack),
ACTION(Box::new(|packet| {
std::fs::File::create("tests/tmp/7.zip")
.unwrap()
.write(&packet.clone().serialize())
.unwrap();
let bytes = packet.clone().serialize();
std::fs::write("tests/tmp/7.tar", &bytes[3..bytes.len()-4]).unwrap();
})),
COBC(Ack),
EDU(Eof),
Expand All @@ -46,10 +44,10 @@ fn returns_result_correctly() -> TestResult {
command::handle_command(&mut com, &mut exec);
assert!(com.is_complete());

std::process::Command::new("unzip")
std::process::Command::new("tar")
.current_dir("./tests/tmp")
.arg("-o")
.arg("7.zip")
.arg("xf")
.arg("7.tar")
.status()?;

assert_eq!(std::fs::read("tests/tmp/3")?, vec![0xde, 0xad]);
Expand Down Expand Up @@ -80,7 +78,7 @@ fn truncate_result() -> TestResult {
command::handle_command(&mut com, &mut exec);
assert!(com.is_complete());

assert!(std::fs::File::open("./data/8_5.zip")?.metadata()?.len() < 1_001_000);
assert!(std::fs::File::open("./data/8_5.tar")?.metadata()?.len() < 1_005_000);

common::cleanup("8");
Ok(())
Expand Down Expand Up @@ -122,7 +120,7 @@ fn stopped_return() -> TestResult {
command::handle_command(&mut com, &mut exec);
assert!(com.is_complete());

assert!(std::fs::File::open("./data/9_5.zip").is_ok());
assert!(std::fs::File::open("./data/9_5.tar").is_ok());

common::cleanup("9");
Ok(())
Expand Down Expand Up @@ -162,7 +160,7 @@ fn result_is_not_deleted_after_corrupted_transfer() -> TestResult {
command::handle_command(&mut com, &mut exec);
assert!(com.is_complete());

assert!(std::fs::File::open("./data/50_0.zip").is_ok());
assert!(std::fs::File::open("./data/50_0.tar").is_ok());

common::cleanup("50");
Ok(())
Expand Down

0 comments on commit 4fce424

Please sign in to comment.