[test] Add tests for config.ValidateStringArrayField and config.IsValidAllowOnlyReposValue#7443
Merged
lpcox merged 3 commits intoJun 12, 2026
Conversation
…OnlyReposValue
Both functions had 0% test coverage. This commit adds comprehensive
table-driven tests covering all branches:
ValidateStringArrayField:
- raw is not []interface{} (optional and required)
- empty []interface{} (optional and required)
- entries that are non-string types (int, nil, bool)
- entries that are empty/whitespace strings
- valid single and multiple string entries
IsValidAllowOnlyReposValue:
- string inputs: all/public (case-insensitive, whitespace), other values
- []interface{} inputs: valid scopes, invalid scopes, duplicates, empty
- default cases: nil, int, bool, map, []string
Coverage change:
- config.ValidateStringArrayField: 0% -> 100%
- config.IsValidAllowOnlyReposValue: 0% -> 100%
- internal/config package overall: 95.9% -> 97.1%
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage in internal/config by adding focused unit tests for two previously untested guard-policy validation helpers (ValidateStringArrayField and IsValidAllowOnlyReposValue) in guard_policy_validation.go.
Changes:
- Added table-driven tests covering success, error, and edge cases for
ValidateStringArrayField. - Added table-driven tests covering
string,[]interface{}, and default-type behaviors forIsValidAllowOnlyReposValue.
Show a summary per file
| File | Description |
|---|---|
| internal/config/guard_policy_string_validation_test.go | Adds new unit tests to cover the two guard policy validation helpers and their key branches. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 13, 2026
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 Coverage Improvement:
ValidateStringArrayFieldandIsValidAllowOnlyReposValueFunctions Analyzed
internal/configValidateStringArrayField,IsValidAllowOnlyReposValueinternal/config/guard_policy_validation.goWhy These Functions?
Both functions were at 0% coverage in the
internal/configpackage. They are exported functions used by the guard pipeline (ininternal/guard/wasm_payload.go) to validate the label_agent policy transport payload. Despite being called from critical security-policy code paths, they had no tests of their own.ValidateStringArrayFieldhas 5 distinct branches (type assertion failure × optional/required, empty array, non-string entry, whitespace entry, valid path).IsValidAllowOnlyReposValuecovers 3 type switch cases (string,[]interface{}, default).Tests Added
requireNonEmpty=falseand=true), whitespace-only stringsstring,nil,int,bool,map), non-string entries, empty/whitespace entriesIsValidAllowOnlyReposValue[]interface{}scope validation paths (valid, invalid, duplicate, empty)IsValidAllowOnlyReposValueCoverage Report
Test Execution
All 44 test cases pass (19 for
ValidateStringArrayField, 25 forIsValidAllowOnlyReposValue):Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 9 domains
The following domains were blocked by the firewall during workflow execution:
172.30.0.50go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inpkg.go.devproxy.golang.orgsum.golang.orgSee Network Configuration for more information.