Skip to content

Commit 794e1cc

Browse files
committed
Add tests between file/pipe mode
1 parent f7dd066 commit 794e1cc

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/compression_e2e.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use linux_perf_data::{CompressionInfo, PerfFileReader, PerfFileRecord};
1+
use linux_perf_data::{CompressionInfo, Error, PerfFileReader, PerfFileRecord};
22
use std::fs::File;
33
use std::io::BufReader;
44

@@ -378,3 +378,37 @@ fn test_zstd_feature_disabled_error() {
378378
);
379379
}
380380
}
381+
382+
/// Test that parse_pipe fails with a clear error when given file format data
383+
#[test]
384+
fn test_parse_pipe_with_file_format_fails() {
385+
let file = File::open("tests/fixtures/sleep.data").unwrap();
386+
let reader = BufReader::new(file);
387+
388+
let result = PerfFileReader::parse_pipe(reader);
389+
assert!(
390+
matches!(result, Err(Error::FileFormatDetectedInPipeMode)),
391+
"Expected FileFormatDetectedInPipeMode error"
392+
);
393+
}
394+
395+
/// Test that parse_file transparently handles pipe format by falling back to parse_pipe
396+
#[test]
397+
fn test_parse_file_with_pipe_format_falls_back() {
398+
let file = File::open("tests/fixtures/sleep_compressed.pipe.data").unwrap();
399+
let reader = BufReader::new(file);
400+
401+
// parse_file should detect pipe format and fall back to parse_pipe
402+
let PerfFileReader {
403+
mut perf_file,
404+
mut record_iter,
405+
} = PerfFileReader::parse_file(reader)
406+
.expect("parse_file should handle pipe format transparently");
407+
408+
// Should be able to read records
409+
let mut count = 0;
410+
while let Some(_record) = record_iter.next_record(&mut perf_file).unwrap() {
411+
count += 1;
412+
}
413+
assert!(count > 0, "Should have read some records");
414+
}

0 commit comments

Comments
 (0)