Skip to content

test(ruletypes): add table-driven unit tests for release phase conver…#6328

Open
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
dakshhhhh16:test/ruletypes-release-phase-coverage
Open

test(ruletypes): add table-driven unit tests for release phase conver…#6328
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
dakshhhhh16:test/ruletypes-release-phase-coverage

Conversation

@dakshhhhh16
Copy link
Copy Markdown
Contributor

@dakshhhhh16 dakshhhhh16 commented Apr 10, 2026

What

Adds pkg/ruletypes/util_test.go with 12 table-driven test cases covering the two public conversion helpers in pkg/ruletypes/util.go that were previously at 0% statement coverage:

Function Coverage before Coverage after
GetPBReleasePhaseFromDBReleaseStatus 0% 100%
GetDBReleaseStatusFromPBReleasePhase 0% 85.7%

The remaining ~14% of GetDBReleaseStatusFromPBReleasePhase is the Scan type-switch fallback path, which is unreachable from valid Go code because db.ReleaseStatus only accepts string or []byte inputs.

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)

  • nil input → RULE_TYPE_RELEASE_PHASE_UNSPECIFIED (no error)
  • alpha, beta, ga, deprecated → correct protobuf enum value
  • Unrecognised db.ReleaseStatus string → error returned

TestGetDBReleaseStatusFromPBReleasePhase (6 cases)

  • ALPHA, BETA, GA, DEPRECATED → correct db.ReleaseStatus constant
  • UNSPECIFIED → defaults to ga (via EnsureDefault())
  • Out-of-range enum value 999 → error wrapped with ErrRuleTypeInvalid

Notes

  • All subtests run with t.Parallel() and are race-clean (go test -race passes)
  • No DB mock, network, or external dependency required — pure function testing
  • Follows the same table-driven pattern used in the adjacent service_test.go

Related

Continues the coverage push toward the project 60% threshold, following #6309 which covered pkg/profiles/models/.

…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.
@dakshhhhh16 dakshhhhh16 requested a review from a team as a code owner April 10, 2026 10:42
@dakshhhhh16
Copy link
Copy Markdown
Contributor Author

@evankanderson
The failing check is a pre-existing flaky test in the webhook package, it uses a 10 ms channel timeout that's tight enough to race on loaded CI runners regardless of changes in this PR. I reproduced it locally under load and it has no relation to the util_test.go added here. Happy to raise a separate PR to bump the timeout if that would help, but feel free to re-run the check in the meantime.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 59.526% (+0.02%) from 59.505% — dakshhhhh16:test/ruletypes-release-phase-coverage into mindersec:main

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.

2 participants