Add tests for correlation_meta
@@ -328,29 +328,11 @@ impl<'value> Iterator for ValueIter<'value> {
#[cfg(test)]
mod test {
use super::*;
- use crate::errors::Result;
+ use crate::Result;
use simd_json::OwnedValue;
use tremor_script::{Object, ValueAndMeta};
- #[test]
- fn value_iters() {
- let mut b = Event {
- data: (Value::array(), 2).into(),
- is_batch: true,
- ..Event::default()
- };
- let e1 = Event {
- data: (1, 2).into(),
- ..Event::default()
- };
- let e2 = Event {
- data: (3, 4).into(),
- ..Event::default()
- };
-
- let merge = move |this: &mut ValueAndMeta<'static>,
- other: ValueAndMeta<'static>|
- -> crate::errors::Result<()> {
+ fn merge(this: &mut ValueAndMeta<'static>, other: ValueAndMeta<'static>) -> Result<()> {
if let Some(ref mut a) = this.value_mut().as_array_mut() {
let mut e = Object::with_capacity(7);
// {"id":1,
@@ -374,7 +356,23 @@ mod test {
a.push(Value::from(e))
};
Ok(())
+ }
+ #[test]
+ fn value_iters() {
+ let mut b = Event {
+ data: (Value::array(), 2).into(),
+ is_batch: true,
+ ..Event::default()
+ };
+ let e1 = Event {
+ data: (1, 2).into(),
+ ..Event::default()
+ };
+ let e2 = Event {
+ data: (3, 4).into(),
+ ..Event::default()
};
+
assert!(b.data.consume(e1.data, merge).is_ok());
assert!(b.data.consume(e2.data, merge).is_ok());
@@ -486,4 +484,24 @@ mod test {
assert_eq!(false, e.is_empty());
Ok(())
}
+ #[test]
+ fn correlation_meta() -> Result<()> {
+ let mut e = Event::default();
+ assert!(e.correlation_meta().is_none());
+ let mut m = Value::object();
+ m.insert("correlation", 1).unwrap();
+ e.data = (Value::null(), m.clone()).into();
+
+ assert_eq!(e.correlation_meta().unwrap(), 1);
+ let mut e2 = Event::default();
+ e2.is_batch = true;
+ e2.data = (Value::array(), m.clone()).into();
+ e2.data.consume(e.data.clone(), merge).unwrap();
+ m.insert("correlation", 2).unwrap();
+ e.data = (Value::null(), m.clone()).into();
+ e2.data.consume(e.clone().data, merge).unwrap();
+ assert_eq!(e2.correlation_meta().unwrap(), Value::from(vec![1, 2]));
+
+ Ok(())
+ }
}
