Skip to content

feat(avro-to-json): add unit tests for wire format config parsing#368

Open
katriendg wants to merge 3 commits intomainfrom
test/359-avro-unit
Open

feat(avro-to-json): add unit tests for wire format config parsing#368
katriendg wants to merge 3 commits intomainfrom
test/359-avro-unit

Conversation

@katriendg
Copy link
Copy Markdown
Collaborator

Description

Extracted a resolve_wire_format pure function from the inline wire format matching logic in avro_init and 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, and unwrap_schema_value — pure functions tested in isolation from WASM host imports.

  • Extracted resolve_wire_format as a pure function returning (WireFormat, Option<String>), where the second element carries the unknown value string for caller-side warning logging
  • Refactored avro_init to delegate wire format resolution to the extracted function, replacing a ~20-line inline match block with a function call plus separate warning log block
  • Added 8 unit tests covering case-insensitive matching ("confluent", "CONFLUENT", "Confluent"), whitespace trimming (" raw "), unknown value defaulting ("invalid"Auto), missing wireFormat (NoneAuto), explicit "auto", and OnceLock first-write-wins semantics
    • All 56 tests pass (48 existing + 8 new) on native target (x86_64-unknown-linux-gnu)

Related Issue

Closes #359

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Blueprint modification or addition
  • Component modification or addition
  • Documentation update
  • CI/CD pipeline change
  • Other (please describe):

Implementation Details

The avro_init function receives a WIT-generated ModuleConfiguration type that is only available when targeting wasm32-wasip2, making direct unit testing impossible with native cargo test. Following the pattern established by existing helpers and Microsoft Learn guidance, the wire format resolution logic was extracted into a pure function that accepts Option<&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

  • Unit tests
  • Terraform plan/apply
  • Blueprint deployment test
  • Integration tests
  • Bug fix includes regression test (see Test Policy)
  • Manual validation tested on running cluster with wireFormat provided, and one with empty omitted wireFormat config setting
  • Other:

All 56 tests pass via cargo test --target x86_64-unknown-linux-gnu in 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

  1. Navigate to src/500-application/512-avro-to-json/operators/avro-to-json/
  2. Run cargo test --target x86_64-unknown-linux-gnu
  3. Verify output shows test result: ok. 56 passed; 0 failed
  4. Confirm resolve_wire_format tests appear in the output with the resolve_wire_format_ and oncelock_ prefixes

Checklist

  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have run terraform fmt on all Terraform code
  • I have run terraform validate on all Terraform code
  • I have run az bicep format on all Bicep code
  • I have run az bicep build to validate all Bicep code
  • I have checked for any sensitive data/tokens that should not be committed
  • Lint checks pass (run applicable linters for changed file types)

Security Review

  • No credentials, secrets, or tokens are hardcoded or logged
  • RBAC and identity changes follow least-privilege principles
  • No new network exposure or public endpoints introduced without justification
  • Dependency additions or updates have been reviewed for known vulnerabilities
  • Container image changes use pinned digests or SHA references

Additional Notes

  • No changes to Cargo.toml or dependencies — the tests use only std::sync::OnceLock from the standard library
  • Documentation checklist item left unchecked — the component README.md is auto-generated and this change does not alter public interfaces

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.
@katriendg katriendg requested a review from a team as a code owner April 8, 2026 11:55
@katriendg katriendg requested a review from auyidi1 April 8, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(avro-to-json): add unit tests for avro_init configuration parsing

3 participants