Skip to content

Dedupe GetFilesWithSuffix and document hash struct precondition - #2690

Open
abrarshivani wants to merge 2 commits into
NVIDIA:mainfrom
abrarshivani:utils-dedupe-getfiles
Open

Dedupe GetFilesWithSuffix and document hash struct precondition#2690
abrarshivani wants to merge 2 commits into
NVIDIA:mainfrom
abrarshivani:utils-dedupe-getfiles

Conversation

@abrarshivani

Copy link
Copy Markdown
Contributor

Description

Two small internal/utils production changes split out of the test-coverage PR #2656 (per review, so production behavior is tracked on its own):

  1. GetFilesWithSuffix appended a path once per matching suffix, so a file matching more than one of the provided suffixes was returned multiple times. It now breaks after the first matching suffix, returning each file at most once. Behavior-identical for the only current caller (which passes the non-overlapping yaml/yml/json); the change guards against future overlapping-suffix callers.
  2. GetObjectHashIgnoreEmptyKeys — documented (no behavior change) that the argument must be a struct or pointer-to-struct, and that other kinds/nil panic, since only struct fields can be enumerated. Matches what all callers already pass.

A test asserts GetFilesWithSuffix returns a single entry for a file matching multiple suffixes.

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Lint checks passing (make lint)
  • Generated assets in-sync (make validate-generated-assets)
  • Go mod artifacts in-sync (make validate-modules)
  • Test cases are added for new code paths

Testing

go test ./internal/utils/...
golangci-lint run ./internal/utils/...   # 0 issues (GOOS=linux)

GetFilesWithSuffix appended a path once per matching suffix, so a file that
matched more than one of the provided suffixes was returned multiple times.
Break after the first matching suffix so each file is returned at most once;
this is behavior-identical for non-overlapping suffixes (the only current
caller passes yaml/yml/json). Add a test asserting the single result.

Also document that GetObjectHashIgnoreEmptyKeys requires a struct (or pointer
to struct) and panics on other kinds, matching what all callers already pass.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
Cover the break-on-first-match path fully: order-independence, single-of-many
match, multiple overlapping-match files, non-matching exclusion, and recursion.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
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.

1 participant