Skip to content

[test] Add tests for config.validateGatewayConfig and validateTrustedBots#3637

Merged
lpcox merged 1 commit intomainfrom
test-coverage/validateGatewayConfig-f3a53f657ea324f7
Apr 14, 2026
Merged

[test] Add tests for config.validateGatewayConfig and validateTrustedBots#3637
lpcox merged 1 commit intomainfrom
test-coverage/validateGatewayConfig-f3a53f657ea324f7

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Coverage Improvement: validateGatewayConfig & validateTrustedBots

Functions Analyzed

  • Package: internal/config
  • Primary Function: validateGatewayConfig
  • Secondary Functions: validateTrustedBots, expandTracingVariables
  • Previous Coverage: Three branches of validateGatewayConfig had zero test coverage; validateTrustedBots had no direct unit tests; expandTracingVariables nil/partial-field paths were untested
  • Complexity: High — validateGatewayConfig has 8 distinct validation branches, with three previously completely uncovered

Why These Functions?

validateGatewayConfig is the central config-validation entry point for gateway configuration in stdin JSON format. The existing TestValidateGatewayConfig covered port, timeout, and payloadDir validation but left three non-trivial branches completely untested:

  1. PayloadSizeThreshold — rejected when < 1 per spec §4.1.3.3, but no test verified the boundary or the error path.
  2. TrustedBots delegation — empty array and whitespace-only entries are spec violations (§4.1.3.4), but validateTrustedBots had no direct unit tests.
  3. OpenTelemetry delegation — validateOpenTelemetryConfig is well-tested in isolation, but the delegation path through validateGatewayConfig was never exercised.

Tests Added

  • TestValidateGatewayConfig_PayloadSizeThreshold — nil (omitted), threshold=1 (boundary), threshold=524288 (default), 0 (rejected), -1 and large negative (rejected)
  • TestValidateGatewayConfig_TrustedBots — nil (omitted), valid list, single bot, empty array (rejected), whitespace-only entry (rejected), empty string entry (rejected), second/third entry invalid (correct index in error)
  • TestValidateGatewayConfig_OpenTelemetry — nil (omitted), valid HTTPS endpoint, traceId+spanId, missing endpoint (rejected), non-HTTPS (rejected), invalid traceId (rejected), all-zero traceId (rejected), invalid spanId (rejected), service name accepted
  • TestValidateTrustedBots — direct unit tests for all 4 branches (nil, empty, whitespace/tab-only, valid, multi-entry index verification)
  • TestExpandTracingVariables_NilConfig — nil fast-path returns nil without panic
  • TestExpandTracingVariables_PartialFields — per-field expansion (endpoint-only, traceId-only, spanId-only, headers-only, all-empty no-op, and undefined-variable errors for each field)

Coverage Improvement

Before: validateGatewayConfig — PayloadSizeThreshold, TrustedBots, OpenTelemetry branches: 0%
After:  All three previously-uncovered branches: 100%

Before: validateTrustedBots — direct unit test coverage: 0%
After:  All 4 branches (nil, empty, whitespace entry, valid): 100%

Before: expandTracingVariables — nil case and 4 individual-field paths: 0%
After:  Nil fast-path + 7 partial-field test cases: 100%

Test Execution

Tests are syntactically correct Go code using table-driven patterns and testify assertions, consistent with the existing test suite. They will execute as part of make test-unit in any environment with modules available.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Generated by Test Coverage Improver · ● 8M ·

Cover three previously-untested branches of validateGatewayConfig:
  - PayloadSizeThreshold: < 1 rejected, >= 1 accepted, nil omitted
  - TrustedBots delegation: empty array, whitespace-only entries, valid bots
  - OpenTelemetry delegation: missing endpoint, non-HTTPS, invalid traceId/spanId

Add direct unit tests for validateTrustedBots (all 4 branches: nil, empty,
whitespace/empty string entry, and valid list).

Add tests for expandTracingVariables nil fast-path and partial-field expansion
(endpoint-only, traceId-only, spanId-only, headers-only, all-empty no-op, and
undefined-variable error paths for each field).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review April 14, 2026 14:44
Copilot AI review requested due to automatic review settings April 14, 2026 14:44
@lpcox lpcox merged commit b23eebf into main Apr 14, 2026
3 checks passed
@lpcox lpcox deleted the test-coverage/validateGatewayConfig-f3a53f657ea324f7 branch April 14, 2026 14:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted unit tests to improve branch coverage for gateway configuration validation helpers in internal/config, focusing on previously untested paths.

Changes:

  • Added table-driven tests for validateGatewayConfig covering PayloadSizeThreshold, TrustedBots, and OpenTelemetry delegation.
  • Added direct unit tests for validateTrustedBots.
  • Added tests for expandTracingVariables nil fast-path and partial-field expansion/error paths.
Show a summary per file
File Description
internal/config/validation_gateway_coverage_test.go New tests covering previously uncovered branches in gateway validation and tracing variable expansion.

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: 1

"github.com/stretchr/testify/require"
)

// helper shared within this file; intPtr is declared in validation_string_patterns_test.go.
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about intPtr is confusing/inaccurate: this file doesn’t define a helper and intPtr is shared across multiple _test.go files via validation_string_patterns_test.go. Consider either removing this comment or rewording it to clearly state that intPtr is a package-level test helper defined in validation_string_patterns_test.go and reused here.

Suggested change
// helper shared within this file; intPtr is declared in validation_string_patterns_test.go.
// intPtr is a package-level test helper defined in
// validation_string_patterns_test.go and reused in this file.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants