Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2b9b375

Browse files
committedMar 26, 2024
Add test for size condition + binary files (#51)
1 parent 5f411b4 commit 2b9b375

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
 

‎tests/integration_tests/size_condition.rs

+10
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,13 @@ fn not_equal_not_matching() {
110110
.run()
111111
.assert_matches(vec![]);
112112
}
113+
114+
#[test]
115+
#[ignore]
116+
fn binary_file() {
117+
TestCase::new_for_json_tests()
118+
.add_binary_file("a", &[255u8, 255u8, 255u8, 255u8])
119+
.add_rule(lines!["files a", "size = 4"])
120+
.run()
121+
.assert_matches(vec!["a"]);
122+
}

‎testutils/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl TestCase {
7575
}
7676
}
7777

78-
pub fn add_raw_file(&mut self, path: &str, text: &str) -> &mut Self {
78+
pub fn add_raw_binary_file(&mut self, path: &str, text: &[u8]) -> &mut Self {
7979
let path = Path::new(path);
8080
let root_path = self.temp_dir.path();
8181

@@ -85,14 +85,23 @@ impl TestCase {
8585

8686
let mut f = File::create(root_path.join(path)).unwrap();
8787

88-
f.write_all(text.as_bytes()).unwrap();
88+
f.write_all(text).unwrap();
8989

9090
self
9191
}
9292

93+
pub fn add_raw_file(&mut self, path: &str, text: &str) -> &mut Self {
94+
self.add_raw_binary_file(path, text.as_bytes());
95+
self
96+
}
97+
9398
pub fn add_file(&mut self, path: &str, text: &str) -> &mut Self {
9499
self.add_raw_file(&("root/".to_owned() + path), text);
100+
self
101+
}
95102

103+
pub fn add_binary_file(&mut self, path: &str, text: &[u8]) -> &mut Self {
104+
self.add_raw_binary_file(&("root/".to_owned() + path), text);
96105
self
97106
}
98107

0 commit comments

Comments
 (0)
Please sign in to comment.