Repository navigation
test(secretmaterial): cover ownership checks and Secret write paths - #3451
Merged
EItanya merged 1 commit intoNov 3, 2026
Merged
Conversation
secretmaterial had no test file of its own. The model and tool service tests reached about 71% of it indirectly, and never ran these branches: - IsOwnedBy: apiVersion, kind, name and UID mismatches, and an owner with no UID - DeleteOwnedSecret: a Secret the owner does not own is left alone, and a missing Secret is not an error - CreateCompanionSecrets: an existing non-Opaque Secret is rejected, and keys merge into an existing owned Secret - ValidateMaterials: an invalid key - error paths of the Get, Create, Update and Delete calls Add direct unit tests: table-driven for the pure functions, and the fake client with interceptor funcs for the Secret-handling functions. Statement coverage of the package goes from about 71% to 100%. Signed-off-by: vedantlavale <vedantlavale@gmail.com>
vedantlavale
force-pushed
the
test/secretmaterial-unit-tests
branch
from
October 30, 2026 05:47
7d53f11 to
66799a1
Compare
vedantlavale
marked this pull request as ready for review
October 30, 2026 05:49
Contributor
Author
|
cc : @timflannagan |
EItanya
approved these changes
Nov 3, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain in the added secretmaterial unit tests.
No open issues 🎉
What changed in this PR
Adds dedicated unit tests for secretmaterial, addressing #3450 by covering Secret ownership checks and write/delete behavior without changing production code.
Changes:
- Adds table-driven tests for material validation, owner references, and ownership matching.
- Tests Secret creation, key merging, rejection of incompatible or unowned Secrets, and deletion safeguards.
- Covers injected client failures and owner rollback behavior.
| File | Description |
|---|---|
go/core/internal/service/secretmaterial/secretmaterial_test.go |
Adds unit tests for validation, ownership, Secret operations, error handling, and rollback. |
Review effort: Balanced
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.
Closes #3450
secretmaterialhad no test file of its own. The model and tool service tests reach about 71% of it, and they never run several branches. This PR addssecretmaterial_test.gofor them.What the new tests cover:
IsOwnedBy: mismatching apiVersion, kind, name and UID, an owner with no UID, and a matching reference among several.DeleteOwnedSecret: a Secret the owner doesn't own is left in place, a missing Secret is not an error, and Get and Delete failures are returned.CreateCompanionSecrets: an existing Secret that isn'tOpaqueis rejected, keys merge into an existing owned Secret, and a Secret owned by someone else is rejected without being changed.CreateOrUpdateOwnedOpaqueSecretandCreateOwnedOpaqueSecret: create, update and error paths. An existing Secret is not overwritten byCreateOwnedOpaqueSecret.ValidateMaterials: invalid secret names and keys, including a bad entry after a good one.OwnerReferenceFor: the apiVersion for a named group and for the core group.The pure functions use table-driven tests. The functions that write Secrets use the fake client with
interceptorto inject failures.Testing
From
go/:go test ./core/internal/service/secretmaterial/ -race -count=1 -coverStatement coverage of the package goes from about 71% (indirect, through the model and tool service tests) to 100%.
gofmtandgo vetare clean. I couldn't rungolangci-lintlocally because the installed binary is built with Go 1.26 and this repo targets 1.27, so I'm relying on CI for lint.No production code changes. The test file is about 430 lines, so I can split it into smaller PRs if you'd prefer.