Skip to content

add tests for sortPatches - #517

Open
magic-peach wants to merge 1 commit into
projectsveltos:mainfrom
magic-peach:test/sort-patches-coverage
Open

magic-peach wants to merge 1 commit into
projectsveltos:mainfrom
magic-peach:test/sort-patches-coverage

Conversation

@magic-peach

Copy link
Copy Markdown

What changed

Adds unit tests for sortPatches in controllers/utils.go, a comparator used to order the patches applied to sveltos-agent and sveltos-applier resources, which had zero test coverage.

Why

sortPatches decides the order patches are applied in, using a multi-field tiebreak across Target.Group, Target.Version, Target.Kind, Target.Namespace, Target.Name, and finally Patch content. A regression in the ordering (for example a wrong field comparison or a broken nil-target case) would change patch application order without producing an obvious error, and would only surface as a hard to reproduce behavioral difference downstream.

How it was tested

Added controllers/utils_test.go (4 specs) covering:

  • nil target ordering relative to a non-nil target
  • Group/Version/Kind/Namespace/Name tie-breaking, checked field by field
  • final tiebreak on patch content when every target field matches

Exposed sortPatches via controllers/export_test.go, following the export_test.go pattern already used elsewhere in the projectsveltos repos.

Ran go build, go vet, and the ginkgo suite locally; all specs pass.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.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