diff --git a/tests/resources/translate/json_column.json b/tests/resources/translate/json_column.json index d6230fd..2594b04 100644 --- a/tests/resources/translate/json_column.json +++ b/tests/resources/translate/json_column.json @@ -28,6 +28,45 @@ "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" + } + } } ] } diff --git a/tests/transpile_avro.rs b/tests/transpile_avro.rs index 883112f..4d364ad 100644 --- a/tests/transpile_avro.rs +++ b/tests/transpile_avro.rs @@ -504,6 +504,58 @@ fn avro_test_json_object() { 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] fn avro_test_map_with_atomics() { let input_data = r#" diff --git a/tests/transpile_bigquery.rs b/tests/transpile_bigquery.rs index ba422f7..e69c75b 100644 --- a/tests/transpile_bigquery.rs +++ b/tests/transpile_bigquery.rs @@ -520,6 +520,44 @@ fn bigquery_test_json_object() { 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] fn bigquery_test_map_with_atomics() { let input_data = r#"