test(subscriber/k8s): add unit and fuzz tests for label helper functions#5537
Open
yoonseo-han wants to merge 5 commits into
Open
test(subscriber/k8s): add unit and fuzz tests for label helper functions#5537yoonseo-han wants to merge 5 commits into
yoonseo-han wants to merge 5 commits into
Conversation
Signed-off-by: Yoonseo Han <yooncer00@gmail.com>
Signed-off-by: Yoonseo Han <yooncer00@gmail.com>
Signed-off-by: Yoonseo Han <yooncer00@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds missing unit and fuzz test coverage for the subscriber’s Kubernetes label helper functions in chaoscenter/subscriber/pkg/k8s, closing the coverage gaps called out in #5536.
Changes:
- Added deterministic unit tests for
(*k8sSubscriber).updateLabels(nil, empty, basic map cases). - Expanded unit tests for
addCustomLabelsto cover unset object labels, nil custom labels, and overwrite behavior. - Added fuzz tests validating invariants for both helpers across randomized inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
chaoscenter/subscriber/pkg/k8s/operations_test.go |
Adds additional unit test cases for addCustomLabels edge/overwrite scenarios. |
chaoscenter/subscriber/pkg/k8s/objects_test.go |
Introduces unit tests for updateLabels covering nil/empty/basic behavior. |
chaoscenter/subscriber/pkg/k8s/labels_fuzz_test.go |
Adds fuzz tests asserting invariants for updateLabels and addCustomLabels. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
The Trivy check is failing for this PR. Could you please create a separate PR for the fix and share the link here once it's ready? |
Author
|
Hi @PriteshKiri . Thanks for the check and rerun Looks like the Trivy check passed after the rerun. Would a seperate PR still be necessary or are we good to proceed? |
Contributor
|
This should be fine @yoonseo-han |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Adds unit tests and fuzz tests for the
updateLabelsandaddCustomLabelslabel helper functions inpkg/k8s.Fixes #5536
The existing test coverage had two gaps:
updateLabelshad no tests of any kindaddCustomLabelshad a single unit test covering only the basic merge scenarioThis PR fills those gaps by introducing a clear separation between unit tests and fuzz tests, where each layer has a distinct responsibility:
Unit tests (
objects_test.go,operations_test.go) — deterministic, named scenarios that document behavioral contracts:updateLabels: nil input, empty mapaddCustomLabels: nil custom labels, object with no prior labels set, key overwrite behaviorFuzz tests (
labels_fuzz_test.go) — invariant verification over random inputs, focused on what the fuzzer can actually vary:FuzzUpdateLabels: verifies output length, everykey=valuepresent, no duplicatesFuzzAddCustomLabels: verifies custom labels always win, non-overlapping existing labels are preservedTypes of changes
What types of changes does your code introduce to Litmus? Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
NA
Special notes for your reviewer:
Each of the tests were tested locally based on the following
Fuzz tests
Unit tests
go test ./pkg/k8s -v