feat(avro-to-json): add unit tests for wire format config parsing#368
Open
feat(avro-to-json): add unit tests for wire format config parsing#368
Conversation
Extract resolve_wire_format pure function from avro_init inline logic and add 8 unit tests covering case-insensitive matching, unknown value defaulting, missing wireFormat, and OnceLock behavior.
…rom Docker builds 🔒 - Generated by Copilot
WilliamBerryiii
approved these changes
Apr 8, 2026
rezatnoMsirhC
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extracted a
resolve_wire_formatpure function from the inline wire format matching logic inavro_initand added 8 unit tests covering all configuration parsing scenarios requested in #359. The refactor separated parsing from logging side-effects, making the logic independently testable while preserving identical runtime behavior.The extraction follows the existing codebase pattern used by
parse_with_schema_inner,strip_confluent_header, andunwrap_schema_value— pure functions tested in isolation from WASM host imports.resolve_wire_formatas a pure function returning(WireFormat, Option<String>), where the second element carries the unknown value string for caller-side warning loggingavro_initto delegate wire format resolution to the extracted function, replacing a ~20-line inline match block with a function call plus separate warning log block"confluent","CONFLUENT","Confluent"), whitespace trimming (" raw "), unknown value defaulting ("invalid"→Auto), missing wireFormat (None→Auto), explicit"auto", andOnceLockfirst-write-wins semanticsx86_64-unknown-linux-gnu)Related Issue
Closes #359
Type of Change
Implementation Details
The
avro_initfunction receives a WIT-generatedModuleConfigurationtype that is only available when targetingwasm32-wasip2, making direct unit testing impossible with nativecargo test. Following the pattern established by existing helpers and Microsoft Learn guidance, the wire format resolution logic was extracted into a pure function that acceptsOption<&str>and returns a tuple.The function signature
(WireFormat, Option<String>)was chosen to decouple parsing from logging: when an unknown value is encountered, the caller receives the raw string and decides how to log it. This preserves the exact warning message format from the original implementation.Testing Performed
wireFormatprovided, and one with empty omittedwireFormatconfig settingAll 56 tests pass via
cargo test --target x86_64-unknown-linux-gnuin the avro-to-json crate directory. The 48 existing tests confirmed no regression from the refactor, and 8 new tests validated all #359 scenarios.Validation Steps
src/500-application/512-avro-to-json/operators/avro-to-json/cargo test --target x86_64-unknown-linux-gnutest result: ok. 56 passed; 0 failedresolve_wire_formattests appear in the output with theresolve_wire_format_andoncelock_prefixesChecklist
terraform fmton all Terraform codeterraform validateon all Terraform codeaz bicep formaton all Bicep codeaz bicep buildto validate all Bicep codeSecurity Review
Additional Notes
std::sync::OnceLockfrom the standard library