Skip to content

Add error path and edge case tests for envelope package #7

@lanycrost

Description

@lanycrost

Problem statement

The envelope package has 78.8% statement coverage with 4 tests, but all error paths and several important edge cases are untested.

Uncovered error paths (0 hits in coverage)

  • Marshal(nil) — line 77-79
  • Unmarshal("") (empty payload) — line 92-94
  • Unmarshal(invalidJSON) — line 96-98
  • FromBinaryFrame(nil) — line 124-126
  • FromBinaryFrame with invalid JSON payload — line 131-133
  • ToBinaryFrame when Marshal fails — line 108-110

Untested edge cases

  • Empty envelope (&Envelope{}) with no fields set
  • Nil vs empty Payload (nil vs json.RawMessage(nil) vs json.RawMessage("null"))
  • Kind defaulting: no default when no payload/inputs/transports
  • Kind defaulting: triggered by Inputs alone, or Transports alone
  • Explicit Version is preserved, not overwritten
  • Timestamp conversion: int64uint64 with negative values in ToBinaryFrame
  • Timestamp conversion: uint64int64 overflow in FromBinaryFrame

Untested types

  • HookPayload — zero test coverage
  • TransportDescriptor — only tested as part of round-trip, no isolated tests

Proposed change

Add the following test functions to envelope_test.go:

// Error paths
TestMarshal_ReturnsError_WhenEnvelopeIsNil
TestUnmarshal_ReturnsError_WhenPayloadIsEmpty
TestUnmarshal_ReturnsError_WhenPayloadIsInvalidJSON
TestFromBinaryFrame_ReturnsError_WhenFrameIsNil
TestFromBinaryFrame_ReturnsError_WhenPayloadIsInvalidJSON

// Edge cases
TestMarshal_DoesNotDefaultKind_WhenNoPayloadInputsOrTransports
TestMarshal_DefaultsKind_WhenOnlyInputsPresent
TestMarshal_PreservesExplicitVersion
TestToBinaryFrame_WithNegativeTimestamp
TestFromBinaryFrame_WithMaxUint64Timestamp

// HookPayload
TestHookPayload_MarshalUnmarshal_RoundTrip
TestHookPayload_WithNilData

Affected area

  • Proto definitions
  • Envelope helpers

Compatibility / migration

Test-only changes. No behavior changes.

Additional context

Current coverage: 78.8%. These tests would bring it above 95% and cover all error return paths. Identified during QA review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/envelopeJSON envelope helpers and MIME-contract behavior.good first issueSmall, well-scoped tasks for new contributors.help wantedLooking for community contributions.kind/testsTesting, CI, or verification-only changes.priority/mediumNormal priority item.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions