vector_vrl_tests/
test_enrichment.rs

1use std::collections::HashMap;
2use vrl::value::{ObjectMap, Value};
3
4#[derive(Debug, Clone)]
5struct TestEnrichmentTable;
6
7impl enrichment::Table for TestEnrichmentTable {
8    fn find_table_row<'a>(
9        &self,
10        _case: enrichment::Case,
11        _condition: &'a [enrichment::Condition<'a>],
12        _select: Option<&[String]>,
13        _wildcard: Option<&Value>,
14        _index: Option<enrichment::IndexHandle>,
15    ) -> Result<ObjectMap, String> {
16        let mut result = ObjectMap::new();
17        result.insert("id".into(), Value::from(1));
18        result.insert("firstname".into(), Value::from("Bob"));
19        result.insert("surname".into(), Value::from("Smith"));
20
21        Ok(result)
22    }
23
24    fn find_table_rows<'a>(
25        &self,
26        _case: enrichment::Case,
27        _condition: &'a [enrichment::Condition<'a>],
28        _select: Option<&[String]>,
29        _wildcard: Option<&Value>,
30        _index: Option<enrichment::IndexHandle>,
31    ) -> Result<Vec<ObjectMap>, String> {
32        let mut result1 = ObjectMap::new();
33        result1.insert("id".into(), Value::from(1));
34        result1.insert("firstname".into(), Value::from("Bob"));
35        result1.insert("surname".into(), Value::from("Smith"));
36
37        let mut result2 = ObjectMap::new();
38        result2.insert("id".into(), Value::from(2));
39        result2.insert("firstname".into(), Value::from("Fred"));
40        result2.insert("surname".into(), Value::from("Smith"));
41
42        Ok(vec![result1, result2])
43    }
44
45    fn add_index(
46        &mut self,
47        _case: enrichment::Case,
48        _fields: &[&str],
49    ) -> Result<enrichment::IndexHandle, String> {
50        Ok(enrichment::IndexHandle(1))
51    }
52
53    fn index_fields(&self) -> Vec<(enrichment::Case, Vec<String>)> {
54        Vec::new()
55    }
56
57    /// Returns true if the underlying data has changed and the table needs reloading.
58    fn needs_reload(&self) -> bool {
59        false
60    }
61}
62
63pub(crate) fn test_enrichment_table() -> enrichment::TableRegistry {
64    let registry = enrichment::TableRegistry::default();
65    let mut tables: HashMap<String, Box<dyn enrichment::Table + Send + Sync>> = HashMap::new();
66    tables.insert("test".into(), Box::new(TestEnrichmentTable));
67    registry.load(tables);
68
69    registry
70}