2024-05-24 11:59:03 +03:00
|
|
|
//! Tests that attempt to resolve different metadata files and assert that they parse successfully
|
|
|
|
//! or fail in the expected way.
|
|
|
|
|
2024-05-28 11:50:46 +03:00
|
|
|
use std::fs;
|
2024-06-18 15:18:21 +03:00
|
|
|
use std::path::PathBuf;
|
2024-05-28 11:50:46 +03:00
|
|
|
|
2024-05-24 11:59:03 +03:00
|
|
|
use metadata_resolve::MetadataResolveFlagsInternal;
|
|
|
|
|
2024-06-18 15:18:21 +03:00
|
|
|
#[test_each::file(
|
|
|
|
glob = "crates/metadata-resolve/tests/passing/**/metadata.json",
|
2024-06-21 04:08:07 +03:00
|
|
|
name(segments = 3)
|
2024-06-18 15:18:21 +03:00
|
|
|
)]
|
|
|
|
fn test_passing_metadata(metadata_json_text: &str) -> anyhow::Result<()> {
|
2024-05-24 11:59:03 +03:00
|
|
|
let metadata_resolve_flags_internal = MetadataResolveFlagsInternal {
|
|
|
|
enable_boolean_expression_types: true,
|
2024-06-21 04:08:07 +03:00
|
|
|
enable_aggregate_relationships: true,
|
2024-05-24 11:59:03 +03:00
|
|
|
};
|
|
|
|
|
2024-06-18 15:18:21 +03:00
|
|
|
let metadata_json_value = serde_json::from_str(metadata_json_text)?;
|
2024-05-24 11:59:03 +03:00
|
|
|
|
|
|
|
let metadata = open_dds::traits::OpenDd::deserialize(metadata_json_value)?;
|
|
|
|
let resolved = metadata_resolve::resolve(metadata, &metadata_resolve_flags_internal);
|
|
|
|
|
|
|
|
match resolved {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(msg) => panic!("{msg}"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-13 11:19:35 +03:00
|
|
|
#[test_each::file(
|
|
|
|
glob = "crates/metadata-resolve/tests/failing/**/metadata.json",
|
|
|
|
name(segments = 3)
|
|
|
|
)]
|
2024-05-28 11:50:46 +03:00
|
|
|
#[allow(clippy::needless_pass_by_value)] // must receive a `PathBuf`
|
2024-06-13 11:19:35 +03:00
|
|
|
fn test_failing_metadata(
|
|
|
|
metadata_json_text: &str,
|
|
|
|
metadata_json_path: PathBuf,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
let comparison_folder_path = metadata_json_path.parent().unwrap();
|
2024-05-28 11:50:46 +03:00
|
|
|
let failing_reason = comparison_folder_path.join("expected_error.txt");
|
2024-05-24 11:59:03 +03:00
|
|
|
|
|
|
|
let metadata_resolve_flags_internal = MetadataResolveFlagsInternal {
|
|
|
|
enable_boolean_expression_types: true,
|
2024-06-21 04:08:07 +03:00
|
|
|
enable_aggregate_relationships: true,
|
2024-05-24 11:59:03 +03:00
|
|
|
};
|
|
|
|
|
2024-06-18 15:02:18 +03:00
|
|
|
let error_untrimmed = fs::read_to_string(failing_reason)?;
|
2024-05-24 11:59:03 +03:00
|
|
|
let error = error_untrimmed.trim();
|
|
|
|
|
2024-06-13 11:19:35 +03:00
|
|
|
match serde_json::from_str(metadata_json_text) {
|
2024-05-24 11:59:03 +03:00
|
|
|
Ok(metadata_json_value) => {
|
|
|
|
match open_dds::traits::OpenDd::deserialize(metadata_json_value) {
|
|
|
|
Ok(metadata) => {
|
|
|
|
match metadata_resolve::resolve(metadata, &metadata_resolve_flags_internal) {
|
|
|
|
Ok(_) => panic!("Expected to fail with {error}"),
|
|
|
|
Err(msg) => similar_asserts::assert_eq!(error, msg.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(msg) => similar_asserts::assert_eq!(msg.to_string(), error),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(msg) => {
|
|
|
|
similar_asserts::assert_eq!(msg.to_string(), error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|