diff --git a/zenoh-flow-descriptors/src/flattened/nodes/sink.rs b/zenoh-flow-descriptors/src/flattened/nodes/sink.rs index 4308f4ee..0baedc98 100644 --- a/zenoh-flow-descriptors/src/flattened/nodes/sink.rs +++ b/zenoh-flow-descriptors/src/flattened/nodes/sink.rs @@ -107,3 +107,57 @@ impl FlattenedSinkDescriptor { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_serialize_zenoh() { + let yaml_str = r#" +id: sink-2 +description: sink-2 +zenoh: + kitchen_all: home/kitchen/* +inputs: + - kitchen_all +configuration: null +"#; + let flat_sink: FlattenedSinkDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + + assert!(serde_yaml::to_string(&flat_sink).is_ok()); + } + + #[test] + fn test_serialize_no_configuration() { + let yaml_str = r#" +id: sink-2 +description: sink-2 +library: file:///home/zenoh-flow/nodes/libsink_0.so +inputs: + - in-0 +"#; + + let flat_sink: FlattenedSinkDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + assert!(serde_yaml::to_string(&flat_sink).is_ok()); + } + + #[test] + fn test_serialize_full() { + let yaml_str = r#" +id: "sink-0" +description: "sink-0" +library: file:///home/zenoh-flow/nodes/libsink_0.so +inputs: + - in-0 +configuration: + answer: 42 +"#; + + let flat_sink: FlattenedSinkDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + assert!(serde_yaml::to_string(&flat_sink).is_ok()); + } +} diff --git a/zenoh-flow-descriptors/src/flattened/nodes/source.rs b/zenoh-flow-descriptors/src/flattened/nodes/source.rs index a75adf60..de38260c 100644 --- a/zenoh-flow-descriptors/src/flattened/nodes/source.rs +++ b/zenoh-flow-descriptors/src/flattened/nodes/source.rs @@ -25,6 +25,9 @@ use crate::{ }; /// TODO@J-Loudet +/// - documentation +/// - validation would be a nice addition: what if users decide to write their own yaml/json and write something that is +/// wrong? For instance, assuming a built-in Zenoh Source is wanted, some keys that are not mapped to a subscriber. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FlattenedSourceDescriptor { pub id: NodeId, @@ -108,3 +111,59 @@ impl FlattenedSourceDescriptor { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_serialize_zenoh() { + let yaml_str = r#" +id: source-0 +description: source-0 +zenoh: + kitchen_all: home/kitchen/* +outputs: + - kitchen_all +configuration: null +runtime: null +"#; + let flat_source: FlattenedSourceDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + + assert!(serde_yaml::to_string(&flat_source).is_ok()); + } + + #[test] + fn test_serialize_no_configuration() { + let yaml_str = r#" +id: "source-0" +description: "source-0" +library: file:///home/zenoh-flow/nodes/libsource_0.so +outputs: + - out-0 +"#; + + let flat_source: FlattenedSourceDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + assert!(serde_yaml::to_string(&flat_source).is_ok()); + } + + #[test] + fn test_serialize_full() { + let yaml_str = r#" +id: "source-0" +description: "source-0" +library: file:///home/zenoh-flow/nodes/libsource_0.so +outputs: + - out-0 +runtime: 3dd70f57-feb7-424c-9278-8bc8813c644e +configuration: + answer: 42 +"#; + + let flat_source: FlattenedSourceDescriptor = + serde_yaml::from_str(yaml_str).expect("Failed to deserialise"); + assert!(serde_yaml::to_string(&flat_source).is_ok()); + } +}