Skip to content

Commit

Permalink
test(descriptors): add serialization tests for flattened source/sink
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Loudet <julien.loudet@zettascale.tech>
  • Loading branch information
J-Loudet committed Nov 20, 2023
1 parent 4312e25 commit 816c859
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
54 changes: 54 additions & 0 deletions zenoh-flow-descriptors/src/flattened/nodes/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
59 changes: 59 additions & 0 deletions zenoh-flow-descriptors/src/flattened/nodes/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 816c859

Please sign in to comment.