Skip to content

Commit

Permalink
Merge pull request #105 from monadicus/test-schema
Browse files Browse the repository at this point in the history
test(schema): deserialize spec files
  • Loading branch information
voximity authored Apr 7, 2024
2 parents 0f2998a + 98449e2 commit 8fa6761
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/snops/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ impl Environment {
.collect()
}

/// Deserialize (YAML) many documents into a `Vec` of documents.
pub fn deserialize_bytes(str: &[u8]) -> Result<Vec<ItemDocument>, DeserializeError> {
serde_yaml::Deserializer::from_slice(str)
.enumerate()
.map(|(i, doc)| ItemDocument::deserialize(doc).map_err(|e| DeserializeError { i, e }))
.collect()
}

/// Prepare a test. This will set the current test on the GlobalState.
///
/// **This will error if the current env is not unset before calling to
Expand Down
24 changes: 24 additions & 0 deletions crates/snops/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,27 @@ impl NodeTargets {
}
}
}

#[cfg(test)]
mod test {
use crate::env::Environment;

#[test]
fn deserialize_specs() {
for entry in std::fs::read_dir("../../specs")
.expect("failed to read specs dir")
.map(Result::unwrap)
{
let file_name = entry.file_name();
let name = file_name.to_str().expect("failed to read spec file name");
if !name.ends_with(".yaml") && !name.ends_with(".yml") {
continue;
}

let data = std::fs::read(entry.path()).expect("failed to read spec file");
if let Err(e) = Environment::deserialize_bytes(&data) {
panic!("failed to deserialize spec file {name}: {e}")
}
}
}
}
2 changes: 2 additions & 0 deletions specs/test-timeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ nodes:
---
version: timeline.snarkos.testing.monadic.us/v1

name: test-timeline

timeline:
- duration: 5s
- offline: '*/*'
Expand Down

0 comments on commit 8fa6761

Please sign in to comment.