use crate::core::config::e2e::{ArgMapping, CallConfig};
use crate::core::ir::{FieldDef, TypeDef, TypeRef};
use crate::e2e::fixture::Fixture;
fn envelope_arg() -> ArgMapping {
ArgMapping {
name: "request".into(),
field: "input".into(),
arg_type: "json_object".into(),
optional: false,
owned: true,
element_type: Some("SampleEnvelope".into()),
go_type: None,
vec_inner_is_ref: false,
trait_name: None,
}
}
fn flattened_field(name: &str, target: &str) -> FieldDef {
FieldDef {
name: name.into(),
ty: TypeRef::Named(target.into()),
serde_flatten: true,
..Default::default()
}
}
fn cyclic_flatten_types() -> Vec<TypeDef> {
vec![
TypeDef {
name: "SampleEnvelope".into(),
fields: vec![
flattened_field("header", "SampleHeader"),
flattened_field("body", "SampleBody"),
],
..Default::default()
},
TypeDef {
name: "SampleHeader".into(),
fields: vec![
FieldDef {
name: "payload".into(),
ty: TypeRef::Bytes,
..Default::default()
},
flattened_field("body", "SampleBody"),
],
..Default::default()
},
TypeDef {
name: "SampleBody".into(),
fields: vec![FieldDef {
name: "payload".into(),
ty: TypeRef::Named("SampleHeader".into()),
..Default::default()
}],
..Default::default()
},
]
}
fn scan(input: serde_json::Value) -> bool {
let fixture = Fixture {
input,
..Default::default()
};
let call = CallConfig {
args: vec![envelope_arg()],
..Default::default()
};
super::fixture_uses_test_documents(&fixture, &call, &cyclic_flatten_types(), &[])
}
#[test]
fn cycle_cut_result_is_not_cached_for_a_cycle_free_sibling_branch() {
assert!(scan(
serde_json::json!({"payload": {"payload": "documents/sample.bin"}})
));
}
#[test]
fn cyclic_flatten_graph_without_a_document_path_reports_no_file_input() {
assert!(!scan(serde_json::json!({"payload": {"payload": "inline text"}})));
}