Skip to content

Improve test coverage: untested branches #303

Description

@darccio

Current coverage is ~85.7%. The branches below were identified by running go test -coverprofile and inspecting uncovered statements. Each item is a distinct, reachable (or questionably reachable) code path with no test.

mergo.goisEmptyValue

  • case reflect.Func: return v.IsNil() (line 57) — covered by TestMergeFuncField added in the same scan session
  • case reflect.Ptr/Interface + shouldDereference=falsereturn false (line 55–56) — non-nil pointer with WithoutDereference

merge.godeepMerge

Error propagation (require a transformer that returns an error)

  • Struct field loop: error returned from recursive deepMerge (line 93)
  • Map value (struct/ptr/map kind): error from deepMerge (line 151)
  • Map value (sliceDeepCopy loop): error from deepMerge (line 187)
  • Top-level slice (sliceDeepCopy loop): error from deepMerge (line 245)
  • Pointer dereference: error from deepMerge(dst.Elem(), src.Elem()) (line 267)

Slice handling

  • AppendSlice type-mismatch for top-level slices — "cannot append two slice with different type" (line 230–232); only reachable by calling deepMerge directly, not via the public API (which rejects mismatched types earlier in resolveValues)
  • sliceDeepCopy for slices stored as map values (line 174–192) — tested for struct fields but not map values

Map handling

  • Re-initialise nil dst map before SetMapIndex when both src and dst enter as nil (line 207–209)

Pointer / interface handling

  • dst.Elem().Type() == src.Type() branch: interface dst, non-pointer src of matching concrete type (line 275–278)
  • ErrDifferentArgumentsTypes inside pointer/interface handling (line 279–281)
  • Both dst and src are reflect.Interface, non-nil, no overwrite, same element kind (line 292–296)

mergo.goresolveValues

  • ErrNotSupported: pointer-to-primitive passed to _map (line 71–73)

map.go_map

  • ErrNonPointerArgument for Map() (line 144–146) — tested for Merge() but not Map()
  • resolveValues error in _map: nil dst or src passed to Map() (line 157–159)
  • ErrExpectedMapAsDestination: struct src, non-map dst (e.g. a slice) (line 167–169)
  • ErrExpectedStructAsDestination: map src, non-struct dst (e.g. a slice) (line 171–173)
  • ErrNotSupported in _map: src is neither struct nor map (line 174–175)

map.godeepMap

  • Empty-string guard in changeInitialCase (line 19–21) — no empty-string map keys in existing tests
  • Cycle detection (line 41–44) — no self-referential struct tests
  • !srcElement.IsValid() for nil map values (line 98–100)
  • dstKind == Interface branch (line 105–108)
  • srcKind == Map recursive deepMap branch for nested map→struct (line 109–112)
  • Error from deepMerge in struct case (line 102–104)
  • dstKind == Ptr && srcElement.CanAddr() (line 91–95) — likely unreachable; map values are never addressable in Go (the comment in the source says "Can this work? I guess it can't.")

Defensive / likely unreachable

  • !srcElement.IsValid() inside map key iteration (line 120) — map keys always produce valid values
  • !srcElement.CanInterface() for map elements (line 134) — map values are always interfaceable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions