object metric: Add additional test to ensure avro fails

This commit is contained in:
Jan-Erik Rediger 2024-02-05 16:11:51 +01:00 коммит произвёл Jan-Erik Rediger
Родитель 3f97a83225
Коммит 43733c1352
3 изменённых файлов: 129 добавлений и 0 удалений

Просмотреть файл

@ -28,6 +28,45 @@
"json_object_path_regex": "an_object_name" "json_object_path_regex": "an_object_name"
} }
} }
},
{
"name": "test_json_object_no_avro_support",
"compatible": false,
"test": {
"avro": {
"fields": [
{
"default": null,
"name": "an_object_name",
"type": [
{
"type": "null"
},
{
"type": "string"
}
]
}
],
"name": "root",
"type": "record"
},
"bigquery": "no schema -- we need it to panic",
"json": {
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
}
},
"context": {
"json_object_path_regex": "an_object_name"
}
}
} }
] ]
} }

Просмотреть файл

@ -504,6 +504,58 @@ fn avro_test_json_object() {
convert_avro(&input, context); convert_avro(&input, context);
} }
#[test]
#[should_panic]
fn avro_test_json_object_no_avro_support() {
let input_data = r#"
{
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
}
}
"#;
let expected_data = r#"
{
"fields": [
{
"default": null,
"name": "an_object_name",
"type": [
{
"type": "null"
},
{
"type": "string"
}
]
}
],
"name": "root",
"type": "record"
}
"#;
let mut context = Context {
..Default::default()
};
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
if expected.is_null() {
// No expected data = no avro support
return;
}
assert_eq!(expected, convert_avro(&input, context.clone()));
context.resolve_method = ResolveMethod::Panic;
convert_avro(&input, context);
}
#[test] #[test]
fn avro_test_map_with_atomics() { fn avro_test_map_with_atomics() {
let input_data = r#" let input_data = r#"

Просмотреть файл

@ -520,6 +520,44 @@ fn bigquery_test_json_object() {
convert_bigquery(&input, context); convert_bigquery(&input, context);
} }
#[test]
#[should_panic]
fn bigquery_test_json_object_no_avro_support() {
let input_data = r#"
{
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
}
}
"#;
let expected_data = r#"
"no schema -- we need it to panic"
"#;
let context_data = r#"
{
"json_object_path_regex": "an_object_name"
}
"#;
let context: Value = serde_json::from_str(context_data).unwrap();
let mut context: Context = if context.is_null() {
Default::default()
} else {
serde_json::from_value(context).unwrap()
};
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_bigquery(&input, context.clone()));
context.resolve_method = ResolveMethod::Panic;
convert_bigquery(&input, context);
}
#[test] #[test]
fn bigquery_test_map_with_atomics() { fn bigquery_test_map_with_atomics() {
let input_data = r#" let input_data = r#"