1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
//! Implements generic filtering based on the [`RuleCondition`] DSL.
//!
//! Multiple generic filters can be defined and they are going to be checked in FIFO order. The
//! first one that matches, will result in the event being discarded with a [`FilterStatKey`]
//! identifying the matching filter.

use std::iter::FusedIterator;

use crate::{FilterStatKey, GenericFilterConfig, GenericFiltersConfig, GenericFiltersMap};

use relay_protocol::{Getter, RuleCondition};

/// Maximum supported version of the generic filters schema.
///
/// If the version in the project config is higher, no generic filters are applied.
const MAX_SUPPORTED_VERSION: u16 = 1;

/// Returns whether the given generic config versions are supported.
pub fn are_generic_filters_supported(
    global_filters_version: Option<u16>,
    project_filters_version: u16,
) -> bool {
    global_filters_version.map_or(true, |v| v <= MAX_SUPPORTED_VERSION)
        && project_filters_version <= MAX_SUPPORTED_VERSION
}

/// Checks events by patterns in their error messages.
fn matches<F: Getter>(item: &F, condition: Option<&RuleCondition>) -> bool {
    // TODO: the condition DSL needs to be extended to support more complex semantics, such as
    //  collections operations.
    condition.map_or(false, |condition| condition.matches(item))
}

/// Filters events by any generic condition.
///
/// Note that conditions may have type-specific getter strings, e.g. `"event.some_field"`. In order
/// to make such a generic filter apply to non-Event types, make sure that the [`Getter`] implementation
/// for that type maps `"event.some_field"` to the corresponding field on that type.
pub(crate) fn should_filter<F: Getter>(
    item: &F,
    project_filters: &GenericFiltersConfig,
    global_filters: Option<&GenericFiltersConfig>,
) -> Result<(), FilterStatKey> {
    let filters = merge_generic_filters(
        project_filters,
        global_filters,
        #[cfg(test)]
        MAX_SUPPORTED_VERSION,
    );

    for filter_config in filters {
        if filter_config.is_enabled && matches(item, filter_config.condition) {
            return Err(FilterStatKey::GenericFilter(filter_config.id.to_owned()));
        }
    }

    Ok(())
}

/// Returns an iterator that yields merged generic configs.
///
/// Since filters of project and global configs are complementary and don't
/// provide much value in isolation, both versions must match
/// [`MAX_SUPPORTED_VERSION`] to be compatible.  If filters aren't compatible,
/// an empty iterator is returned.
///
/// If filters are compatible, an iterator over all filters is returned. This
/// iterator yields filters according to the principles below:
/// - Filters from project configs are evaluated before filters from global
///   configs.
/// - No duplicates: once a filter is evaluated (yielded or skipped), no filter
///   with the same id is evaluated again.
/// - If a filter with the same id exists in projects and global configs, both
///   are merged and the filter is yielded. Values from the filter in the project
///   config are prioritized.
fn merge_generic_filters<'a>(
    project: &'a GenericFiltersConfig,
    global: Option<&'a GenericFiltersConfig>,
    #[cfg(test)] max_supported_version: u16,
) -> impl Iterator<Item = GenericFilterConfigRef<'a>> {
    #[cfg(not(test))]
    let max_supported_version = MAX_SUPPORTED_VERSION;

    let is_supported = project.version <= max_supported_version
        && global.map_or(true, |gf| gf.version <= max_supported_version);

    is_supported
        .then(|| {
            DynamicGenericFiltersConfigIter::new(&project.filters, global.map(|gc| &gc.filters))
        })
        .into_iter()
        .flatten()
}

/// Iterator over the generic filters of the project and global configs.
struct DynamicGenericFiltersConfigIter<'a> {
    /// Generic project filters.
    project: &'a GenericFiltersMap,
    /// Index of the next filter in project configs to evaluate.
    project_index: usize,
    /// Generic global filters.
    global: Option<&'a GenericFiltersMap>,
    /// Index of the next filter in global configs to evaluate.
    global_index: usize,
}

impl<'a> DynamicGenericFiltersConfigIter<'a> {
    pub fn new(project: &'a GenericFiltersMap, global: Option<&'a GenericFiltersMap>) -> Self {
        DynamicGenericFiltersConfigIter {
            project,
            project_index: 0,
            global,
            global_index: 0,
        }
    }
}

impl<'a> Iterator for DynamicGenericFiltersConfigIter<'a> {
    type Item = GenericFilterConfigRef<'a>;

    fn next(&mut self) -> Option<Self::Item> {
        if let Some((id, filter)) = self.project.get_index(self.project_index) {
            self.project_index += 1;
            let merged = merge_filters(filter, self.global.and_then(|gf| gf.get(id)));
            return Some(merged);
        }

        loop {
            let (id, filter) = self.global?.get_index(self.global_index)?;
            self.global_index += 1;
            if !self.project.contains_key(id) {
                return Some(filter.into());
            }
        }
    }
}

impl<'a> FusedIterator for DynamicGenericFiltersConfigIter<'a> {}

/// Merges the two filters with the same id, prioritizing values from the primary.
///
/// It's assumed both filters share the same id. The returned filter will have
/// the primary filter's ID.
fn merge_filters<'a>(
    primary: &'a GenericFilterConfig,
    secondary: Option<&'a GenericFilterConfig>,
) -> GenericFilterConfigRef<'a> {
    GenericFilterConfigRef {
        id: primary.id.as_str(),
        is_enabled: primary.is_enabled,
        condition: primary
            .condition
            .as_ref()
            .or(secondary.and_then(|filter| filter.condition.as_ref())),
    }
}

#[derive(Debug, Default, PartialEq)]
struct GenericFilterConfigRef<'a> {
    id: &'a str,
    is_enabled: bool,
    condition: Option<&'a RuleCondition>,
}

impl<'a> From<&'a GenericFilterConfig> for GenericFilterConfigRef<'a> {
    fn from(value: &'a GenericFilterConfig) -> Self {
        GenericFilterConfigRef {
            id: value.id.as_str(),
            is_enabled: value.is_enabled,
            condition: value.condition.as_ref(),
        }
    }
}

#[cfg(test)]
mod tests {

    use super::*;

    use relay_event_schema::protocol::{Event, LenientString};
    use relay_protocol::Annotated;

    fn mock_filters() -> GenericFiltersMap {
        vec![
            GenericFilterConfig {
                id: "firstReleases".to_string(),
                is_enabled: true,
                condition: Some(RuleCondition::eq("event.release", "1.0")),
            },
            GenericFilterConfig {
                id: "helloTransactions".to_string(),
                is_enabled: true,
                condition: Some(RuleCondition::eq("event.transaction", "/hello")),
            },
        ]
        .into()
    }

    #[test]
    fn test_should_filter_match_rules() {
        let config = GenericFiltersConfig {
            version: 1,
            filters: mock_filters(),
        };

        // Matching first rule.
        let event = Event {
            release: Annotated::new(LenientString("1.0".to_string())),
            ..Default::default()
        };
        assert_eq!(
            should_filter(&event, &config, None),
            Err(FilterStatKey::GenericFilter("firstReleases".to_string()))
        );

        // Matching second rule.
        let event = Event {
            transaction: Annotated::new("/hello".to_string()),
            ..Default::default()
        };
        assert_eq!(
            should_filter(&event, &config, None),
            Err(FilterStatKey::GenericFilter(
                "helloTransactions".to_string()
            ))
        );
    }

    #[test]
    fn test_should_filter_fifo_match_rules() {
        let config = GenericFiltersConfig {
            version: 1,
            filters: mock_filters(),
        };

        // Matching both rules (first is taken).
        let event = Event {
            release: Annotated::new(LenientString("1.0".to_string())),
            transaction: Annotated::new("/hello".to_string()),
            ..Default::default()
        };
        assert_eq!(
            should_filter(&event, &config, None),
            Err(FilterStatKey::GenericFilter("firstReleases".to_string()))
        );
    }

    #[test]
    fn test_should_filter_match_no_rules() {
        let config = GenericFiltersConfig {
            version: 1,
            filters: mock_filters(),
        };

        // Matching no rule.
        let event = Event {
            transaction: Annotated::new("/world".to_string()),
            ..Default::default()
        };
        assert_eq!(should_filter(&event, &config, None), Ok(()));
    }

    #[test]
    fn test_should_filter_with_higher_config_version() {
        let config = GenericFiltersConfig {
            // We simulate receiving a higher configuration version, which we don't support.
            version: MAX_SUPPORTED_VERSION + 1,
            filters: mock_filters(),
        };

        let event = Event {
            release: Annotated::new(LenientString("1.0".to_string())),
            transaction: Annotated::new("/hello".to_string()),
            ..Default::default()
        };
        assert_eq!(should_filter(&event, &config, None), Ok(()));
    }

    #[test]
    fn test_should_filter_from_global_filters() {
        let project = GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: "firstReleases".to_string(),
                is_enabled: true,
                condition: Some(RuleCondition::eq("event.release", "1.0")),
            }]
            .into(),
        };

        let global = GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: "helloTransactions".to_string(),
                is_enabled: true,
                condition: Some(RuleCondition::eq("event.transaction", "/hello")),
            }]
            .into(),
        };

        let event = Event {
            transaction: Annotated::new("/hello".to_string()),
            ..Default::default()
        };

        assert_eq!(
            should_filter(&event, &project, Some(&global)),
            Err(FilterStatKey::GenericFilter(
                "helloTransactions".to_string()
            ))
        );
    }

    fn empty_filter() -> GenericFiltersConfig {
        GenericFiltersConfig {
            version: 1,
            filters: GenericFiltersMap::new(),
        }
    }

    /// Returns a complete and enabled [`GenericFiltersConfig`].
    fn enabled_filter(id: &str) -> GenericFiltersConfig {
        GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: id.to_owned(),
                is_enabled: true,
                condition: Some(RuleCondition::eq("event.exceptions", "myError")),
            }]
            .into(),
        }
    }

    /// Returns an enabled flag of a [`GenericFiltersConfig`].
    fn enabled_flag_filter(id: &str) -> GenericFiltersConfig {
        GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: id.to_owned(),
                is_enabled: true,
                condition: None,
            }]
            .into(),
        }
    }

    /// Returns a complete but disabled [`GenericFiltersConfig`].
    fn disabled_filter(id: &str) -> GenericFiltersConfig {
        GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: id.to_owned(),
                is_enabled: false,
                condition: Some(RuleCondition::eq("event.exceptions", "myError")),
            }]
            .into(),
        }
    }

    /// Returns a disabled flag of a [`GenericFiltersConfig`].
    fn disabled_flag_filter(id: &str) -> GenericFiltersConfig {
        GenericFiltersConfig {
            version: 1,
            filters: vec![GenericFilterConfig {
                id: id.to_owned(),
                is_enabled: false,
                condition: None,
            }]
            .into(),
        }
    }

    #[test]
    fn test_no_combined_when_unsupported_project_version() {
        let mut project = enabled_filter("unsupported-project");
        project.version = 2;
        let global = enabled_filter("supported-global");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq(None.into_iter()));
    }

    #[test]
    fn test_no_combined_when_unsupported_project_version_no_global() {
        let mut project = enabled_filter("unsupported-project");
        project.version = 2;
        assert!(merge_generic_filters(&project, None, 1).eq(None.into_iter()));
    }

    #[test]
    fn test_no_combined_when_unsupported_global_version() {
        let project = enabled_filter("supported-project");
        let mut global = enabled_filter("unsupported-global");
        global.version = 2;
        assert!(merge_generic_filters(&project, Some(&global), 1).eq(None.into_iter()));
    }

    #[test]
    fn test_no_combined_when_unsupported_project_and_global_version() {
        let mut project = enabled_filter("unsupported-project");
        project.version = 2;
        let mut global = enabled_filter("unsupported-global");
        global.version = 2;
        assert!(merge_generic_filters(&project, Some(&global), 1).eq(None.into_iter()));
    }

    #[test]
    fn test_both_combined_when_supported_project_and_global_version() {
        let project = enabled_filter("supported-project");
        let global = enabled_filter("supported-global");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([
            project.filters.first().unwrap().1.into(),
            global.filters.first().unwrap().1.into()
        ]
        .into_iter()));
    }

    #[test]
    fn test_project_combined_when_duplicated_filter_project_and_global() {
        let project = enabled_filter("filter");
        let global = enabled_filter("filter");
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_no_combined_when_empty_project_and_global() {
        let project = empty_filter();
        let global = empty_filter();
        assert!(merge_generic_filters(&project, Some(&global), 1).eq(None.into_iter()));
    }

    #[test]
    fn test_global_combined_when_empty_project_disabled_global_filter() {
        let project = empty_filter();
        let global = disabled_filter("disabled-global");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([global
            .filters
            .first()
            .unwrap()
            .1
            .into()]
        .into_iter()));
    }

    #[test]
    fn test_global_combined_when_empty_project_enabled_global_filters() {
        let project = empty_filter();
        let global = enabled_filter("enabled-global");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([global
            .filters
            .first()
            .unwrap()
            .1
            .into()]
        .into_iter()));
    }

    #[test]
    fn test_global_combined_when_empty_project_enabled_flag_global() {
        let project = empty_filter();
        let global = enabled_flag_filter("skip");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([global
            .filters
            .first()
            .unwrap()
            .1
            .into()]));
    }

    #[test]
    fn test_project_combined_when_disabled_project_empty_global() {
        let project = disabled_filter("disabled-project");
        let global = empty_filter();
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_project_combined_when_disabled_project_missing_global() {
        let project = disabled_filter("disabled-project");
        assert!(merge_generic_filters(&project, None, 1).eq([project
            .filters
            .first()
            .unwrap()
            .1
            .into(),]
        .into_iter()));
    }

    #[test]
    fn test_both_combined_when_different_disabled_project_and_global() {
        let project = disabled_filter("disabled-project");
        let global = disabled_filter("disabled-global");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([
            project.filters.first().unwrap().1.into(),
            global.filters.first().unwrap().1.into()
        ]));
    }

    #[test]
    fn test_project_combined_duplicated_disabled_project_and_global() {
        let project = disabled_filter("filter");
        let global = disabled_filter("filter");
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()])
        );
    }

    #[test]
    fn test_merged_combined_when_disabled_project_enabled_global() {
        let project = disabled_filter("filter");
        let global = enabled_filter("filter");
        let expected = &GenericFilterConfig {
            id: "filter".to_owned(),
            is_enabled: false,
            condition: global.filters.first().unwrap().1.condition.clone(),
        };
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([expected.into()].into_iter()));
    }

    #[test]
    fn test_no_combined_when_enabled_flag_project_empty_global() {
        let project = enabled_flag_filter("filter");
        let global = empty_filter();
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_project_combined_when_enabled_flag_project_missing_global() {
        let project = enabled_flag_filter("filter");
        assert!(merge_generic_filters(&project, None, 1).eq([project
            .filters
            .first()
            .unwrap()
            .1
            .into()]
        .into_iter()));
    }

    #[test]
    fn test_project_combined_when_disabled_flag_project_empty_global() {
        let project = disabled_flag_filter("filter");
        let global = empty_filter();
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()])
        );
    }

    #[test]
    fn test_project_combined_when_disabled_flag_project_missing_global() {
        let project = disabled_flag_filter("filter");
        assert!(merge_generic_filters(&project, None, 1).eq([project
            .filters
            .first()
            .unwrap()
            .1
            .into()]));
    }

    #[test]
    fn test_project_combined_when_enabled_project_empty_global() {
        let project = enabled_filter("enabled-project");
        let global = empty_filter();
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_project_combined_when_enabled_project_missing_global() {
        let project = enabled_filter("enabled-project");
        assert!(merge_generic_filters(&project, None, 1).eq([project
            .filters
            .first()
            .unwrap()
            .1
            .into()]
        .into_iter()));
    }

    #[test]
    fn test_merged_combined_when_enabled_flag_project_disabled_global() {
        let project = enabled_flag_filter("filter");
        let global = disabled_filter("filter");
        let expected = &GenericFilterConfig {
            id: "filter".to_owned(),
            is_enabled: true,
            condition: global.filters.first().unwrap().1.condition.clone(),
        };
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([expected.into()].into_iter()));
    }

    #[test]
    fn test_global_combined_when_disabled_flag_project_disabled_global() {
        let project = disabled_flag_filter("filter");
        let global = disabled_filter("filter");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([global
            .filters
            .first()
            .unwrap()
            .1
            .into()]));
    }

    #[test]
    fn test_project_combined_when_enabled_project_disabled_global() {
        let project = enabled_filter("filter");
        let global = disabled_filter("filter");
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_global_combined_when_enabled_flag_project_enabled_global() {
        let project = enabled_flag_filter("filter");
        let global = enabled_filter("filter");
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([global
            .filters
            .first()
            .unwrap()
            .1
            .into()]
        .into_iter()));
    }

    #[test]
    fn test_merged_combined_when_disabled_flag_project_enabled_global() {
        let project = disabled_flag_filter("filter");
        let global = enabled_filter("filter");
        let expected = &GenericFilterConfig {
            id: "filter".to_owned(),
            is_enabled: false,
            condition: global.filters.first().unwrap().1.condition.clone(),
        };
        assert!(merge_generic_filters(&project, Some(&global), 1).eq([expected.into()].into_iter()));
    }

    #[test]
    fn test_project_combined_when_enabled_project_enabled_flag_global() {
        let project = enabled_filter("filter");
        let global = enabled_flag_filter("filter");
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_project_combined_when_enabled_flags_project_and_global() {
        let project = enabled_flag_filter("filter");
        let global = enabled_flag_filter("filter");
        assert!(
            merge_generic_filters(&project, Some(&global), 1).eq([project
                .filters
                .first()
                .unwrap()
                .1
                .into()]
            .into_iter())
        );
    }

    #[test]
    fn test_multiple_combined_filters() {
        let project = GenericFiltersConfig {
            version: 1,
            filters: vec![
                GenericFilterConfig {
                    id: "0".to_owned(),
                    is_enabled: true,
                    condition: Some(RuleCondition::eq("event.exceptions", "myError")),
                },
                GenericFilterConfig {
                    id: "1".to_owned(),
                    is_enabled: true,
                    condition: None,
                },
                GenericFilterConfig {
                    id: "2".to_owned(),
                    is_enabled: true,
                    condition: Some(RuleCondition::eq("event.exceptions", "myError")),
                },
            ]
            .into(),
        };
        let global = GenericFiltersConfig {
            version: 1,
            filters: vec![
                GenericFilterConfig {
                    id: "1".to_owned(),
                    is_enabled: false,
                    condition: Some(RuleCondition::eq("event.exceptions", "myOtherError")),
                },
                GenericFilterConfig {
                    id: "3".to_owned(),
                    is_enabled: false,
                    condition: Some(RuleCondition::eq("event.exceptions", "myLastError")),
                },
            ]
            .into(),
        };

        let expected0 = &project.filters[0];
        let expected1 = &GenericFilterConfig {
            id: "1".to_owned(),
            is_enabled: true,
            condition: Some(RuleCondition::eq("event.exceptions", "myOtherError")),
        };
        let expected2 = &project.filters[2];
        let expected3 = &global.filters[1];

        assert!(merge_generic_filters(&project, Some(&global), 1).eq([
            expected0.into(),
            expected1.into(),
            expected2.into(),
            expected3.into()
        ]
        .into_iter()));
    }
}