[test-improver] Improve tests for config package (GuardPolicyConfig)#1656
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for config package (GuardPolicyConfig)#1656github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Add comprehensive unit tests for the GuardPolicyConfig type in guard_policy.go which had no direct test coverage: - TestNewGuardPolicyConfig: nil/empty/non-nil policies handling - TestGuardPolicyConfig_GetPolicy: service lookup, type assertions, nil handling, non-map values - TestGuardPolicyConfig_HasPolicy: existence checks for all cases - TestGuardPolicyConfig_IsEmpty: empty/non-empty detection - TestServerConfig_GetGuardPolicies: helper method integration - TestGuardPolicyConfig_GetPolicy_TypeAssertions: boolean, integer, slice, and empty map values Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Test Improvements:
guard_policy_test.goFile Analyzed
internal/config/guard_policy_test.go(new file)internal/config/guard_policy.gointernal/configWhy This File?
The
guard_policy.gofile provides theGuardPolicyConfigtype — a type-safe wrapper around the rawmap[string]interface{}guard policies. It has 5 public methods (NewGuardPolicyConfig,GetPolicy,HasPolicy,IsEmpty,GetGuardPolicies) that had zero direct unit test coverage.The existing
config_guardpolicies_test.gofile tests guard policy config loading end-to-end (TOML/JSON parsing), but the individual methods ofGuardPolicyConfigwere never tested in isolation. This is significant because:GetPolicyhas a type assertion (.(map[string]interface{})) that can silently returnnilfor wrong typesHasPolicydelegates toGetPolicy, so untested type assertion paths affect bothIsEmptycheckslen()which behaves differently for nil vs empty mapsImprovements Made
1. New Test File:
internal/config/guard_policy_test.goAdded 357 lines of comprehensive unit tests organized into 6 test functions:
TestNewGuardPolicyConfig— 3 sub-tests:nilpolicies creates non-nil config with empty stateTestGuardPolicyConfig_GetPolicy— 9 table-driven cases:nilfor missing servicenilwhen policies isnilnilwhen policies map is emptynilfor non-map value (string, covering type assertion path)nilfornilvalue in mapnilfor empty string service keyTestGuardPolicyConfig_HasPolicy— 6 table-driven cases:truefor existing service with map valuefalsefor missing servicefalsefornilpoliciesfalsefor non-map valuefalsefornilvalue in mapTestGuardPolicyConfig_IsEmpty— 5 table-driven cases:nilpolicies → emptynilvalue → not empty (key exists)TestServerConfig_GetGuardPolicies— 4 sub-tests:nilGuardPoliciesfield returns empty configGuardPoliciesreturns populated config with correct valuesGuardPoliciesreturns empty configHasPolicy,GetPolicywork correctly for all servicesTestGuardPolicyConfig_GetPolicy_TypeAssertions— 5 sub-tests:nil(type assertion branch)nil(type assertion branch)nil(type assertion branch)2. Coverage
NewGuardPolicyConfigGetPolicyHasPolicyIsEmptyGetGuardPolicies3. Test Quality
t.Run)assertfor non-fatal checks,requirefor preconditionsGenerated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests