Skip to content

Commit d46034e

Browse files
committed
test: comparator expectations
Not very comprehensive but provides an option to pickup some errors
1 parent 4c1f951 commit d46034e

20 files changed

+421
-1
lines changed

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ insta = { version = "1.34.0", features = ["ron", "glob", "yaml"] }
4444
pretty_assertions = "1.4.0"
4545
ron = "0.8.1"
4646
rstest = "0.21.0"
47+
strum = { version = "0.26.3", features = ["derive"] }
4748

4849
# If you want to use the bleeding edge version of egui and eframe:
4950
# egui = { git = "https://github.com/emilk/egui", branch = "master" }

src/app/data.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,13 @@ impl TryFrom<&str> for Data {
299299
mod tests {
300300
use std::fmt::{Debug, Display};
301301

302+
use filter::Comparator;
302303
use insta::glob;
303304
use pretty_assertions::assert_eq;
304305
use rstest::{fixture, rstest};
306+
use strum::IntoEnumIterator;
307+
308+
use crate::app::data_display_options::DataDisplayOptions;
305309

306310
use super::*;
307311

@@ -418,5 +422,57 @@ mod tests {
418422
assert_eq!(after, before);
419423
}
420424

421-
// TODO 1: Add tests for filters
425+
#[rstest]
426+
fn comparisons_specific_field(insta_settings: insta::Settings) {
427+
let row0 = create_log_row_no_extra();
428+
let row1 = create_log_row_with_extra();
429+
let mut data = Data {
430+
rows: vec![row0.clone(), row1.clone()],
431+
..Default::default()
432+
};
433+
434+
data.filter = Some(FilterConfig {
435+
search_key: "200".to_string(),
436+
filter_on: filter::FilterOn::Field(FieldSpecifier {
437+
name: "http.status_code".to_string(),
438+
}),
439+
is_case_sensitive: false,
440+
comparator: Default::default(),
441+
});
442+
443+
let display_options = DataDisplayOptions::default();
444+
let common_fields = display_options.common_fields();
445+
446+
for comparator in Comparator::iter() {
447+
data.filter.as_mut().unwrap().comparator = comparator;
448+
data.apply_filter(common_fields);
449+
insta_settings.bind(|| insta::assert_yaml_snapshot!(data));
450+
}
451+
}
452+
453+
#[rstest]
454+
fn comparisons_any(insta_settings: insta::Settings) {
455+
let row0 = create_log_row_no_extra();
456+
let row1 = create_log_row_with_extra();
457+
let mut data = Data {
458+
rows: vec![row0.clone(), row1.clone()],
459+
..Default::default()
460+
};
461+
462+
data.filter = Some(FilterConfig {
463+
search_key: "20".to_string(),
464+
filter_on: filter::FilterOn::Any,
465+
is_case_sensitive: false,
466+
comparator: Default::default(),
467+
});
468+
469+
let display_options = DataDisplayOptions::default();
470+
let common_fields = display_options.common_fields();
471+
472+
for comparator in Comparator::iter() {
473+
data.filter.as_mut().unwrap().comparator = comparator;
474+
data.apply_filter(common_fields);
475+
insta_settings.bind(|| insta::assert_yaml_snapshot!(data));
476+
}
477+
}
422478
}

src/app/data/filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl FilterOn {
3939
}
4040
}
4141

42+
#[cfg_attr(test, derive(strum::EnumIter))]
4243
#[derive(Debug, Default, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Copy)]
4344
pub enum Comparator {
4445
LessThan,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: LessThanEqual
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows: []
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: Equal
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows: []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: GreaterThan
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows:
20+
- 0
21+
- 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: GreaterThanEqual
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows:
20+
- 0
21+
- 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: NotEqual
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows:
20+
- 0
21+
- 1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: src/app/data.rs
3+
expression: data
4+
---
5+
selected_row: ~
6+
filter:
7+
search_key: "20"
8+
filter_on: Any
9+
is_case_sensitive: false
10+
comparator: Contains
11+
rows:
12+
- data:
13+
otel.name: HTTP GET /status
14+
time: time value
15+
- data:
16+
http.status_code: 200
17+
otel.name: HTTP GET /status
18+
time: time value
19+
filtered_rows:
20+
- 1

0 commit comments

Comments
 (0)