test(ruletypes): add table-driven unit tests for release phase conver…#6328
Open
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
Open
test(ruletypes): add table-driven unit tests for release phase conver…#6328dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
Conversation
…sion functions Add pkg/ruletypes/util_test.go with 12 table-driven test cases covering: - GetPBReleasePhaseFromDBReleaseStatus: nil input, all four valid DB statuses (alpha/beta/ga/deprecated), and an invalid status that must error - GetDBReleaseStatusFromPBReleasePhase: all four valid protobuf phases, UNSPECIFIED (which defaults to GA via EnsureDefault), and an out-of-range enum value that must error Both functions were previously at 0% statement coverage. After this change GetPBReleasePhaseFromDBReleaseStatus reaches 100% and GetDBReleaseStatusFromPBReleasePhase reaches 85.7% (the remaining branch requires a Scan type-switch hit that is unreachable from valid Go code). All tests are parallel, race-clean, and require no DB or network mocks.
Contributor
Author
|
@evankanderson |
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.
What
Adds
pkg/ruletypes/util_test.gowith 12 table-driven test cases covering the two public conversion helpers inpkg/ruletypes/util.gothat were previously at 0% statement coverage:GetPBReleasePhaseFromDBReleaseStatusGetDBReleaseStatusFromPBReleasePhaseThe remaining ~14% of
GetDBReleaseStatusFromPBReleasePhaseis theScantype-switch fallback path, which is unreachable from valid Go code becausedb.ReleaseStatusonly acceptsstringor[]byteinputs.Why
These functions are called by controlplane handlers on every rule-type read/write path but were not exercised by any dedicated unit tests, leaving conversion bugs invisible to CI.
Test cases
TestGetPBReleasePhaseFromDBReleaseStatus(6 cases)nilinput →RULE_TYPE_RELEASE_PHASE_UNSPECIFIED(no error)alpha,beta,ga,deprecated→ correct protobuf enum valuedb.ReleaseStatusstring → error returnedTestGetDBReleaseStatusFromPBReleasePhase(6 cases)ALPHA,BETA,GA,DEPRECATED→ correctdb.ReleaseStatusconstantUNSPECIFIED→ defaults toga(viaEnsureDefault())999→ error wrapped withErrRuleTypeInvalidNotes
t.Parallel()and are race-clean (go test -racepasses)service_test.goRelated
Continues the coverage push toward the project 60% threshold, following #6309 which covered
pkg/profiles/models/.