Skip to content

test(util): add unit tests for pkg/util/hash #7142

@goyalpalak18

Description

@goyalpalak18

What type of issue is this?

/kind feature

Issue Description

The pkg/util/hash package currently has 0% test coverage. This package contains the DeepHashObject function which is used by pkg/util/names for
generating deterministic hash-based names for resources like PolicyNames.

Why is this important?

  1. Correctness Risk: If this function produces inconsistent hashes across Go versions or dependency updates, it could cause
    ResourceBinding/PropagationPolicy name collisions or lookup failures.
  2. Regression Detection: Without tests, refactoring or dependency updates could silently break hash consistency.
  3. Test Coverage Gap: The pkg/util/ directory has good test coverage generally, but this package is a blind spot.

Proposed Solution

Add comprehensive unit tests covering:

  • Basic types (strings, integers, booleans, floats)
  • Complex types (structs, maps, slices)
  • Nested structures
  • Nil values and edge cases
  • Hasher reset behavior
  • Determinism verification

Additional context

This is a good first issue as it:

  • Is completely isolated (single utility function)
  • Has clear success criteria (tests pass, 100% coverage)
  • Introduces contributors to Karmada's testing patterns
  • Is low-risk (adding tests cannot break existing functionality)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions