[test-improver] Improve tests for resolve_guard_policy_test.go - #13065
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[test-improver] Improve tests for resolve_guard_policy_test.go#13065github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Convert 32 standalone Test functions into three table-driven test functions (TestNormalizeScopeKind, TestResolveGuardPolicy, TestResolveWriteSinkPolicy), reducing duplication while preserving every existing test case and assertion. Coverage of resolveGuardPolicy, resolveWriteSinkPolicy, and NormalizeScopeKind remains 100%. Co-authored-by: Copilot <[email protected]>
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.
Summary
Refactors
internal/server/resolve_guard_policy_test.goto reduce duplication and improve structure, per the Test Improver workflow.File analyzed:
internal/server/resolve_guard_policy_test.go(505 lines, 32 standaloneTest*functions, no table-driven tests, 0 manual error-check anti-patterns — testify was already used throughout).Improvements made
TestNormalizeScopeKind_*functions into a single table-drivenTestNormalizeScopeKindwitht.Runsubtests (keptTestNormalizeScopeKind_DoesNotMutateInputseparate since it asserts on the input map, not just the result, which doesn't fit the table cleanly).TestResolveGuardPolicy_*functions into a single table-drivenTestResolveGuardPolicy, using an optionalwantPolicyCheckcallback for cases needing to inspect the parsed policy contents (vs. simple identity comparison for pass-through cases).TestResolveWriteSinkPolicy_*functions into a single table-drivenTestResolveWriteSinkPolicy.GuardPolicySourcedefaults to"override", why an empty policy struct is invalid, legacy-fallback semantics, etc.) — no test coverage was dropped.Coverage before/after
Coverage of the exercised functions was already 100% and remains 100% after the refactor (verified via
go tool cover -func):Overall
internal/serverpackage coverage unchanged at 95.2%.Test output
Also verified:
go test -count=3 ./internal/server/...— passes (no flakiness)go vet ./...— cleangofmt -l internal/server/resolve_guard_policy_test.go— no output (already formatted)make buildandmake lint— pass (golangci-lint binary unavailable in this sandbox; gofmt check passed)