Skip to content

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

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test-coverage/validateGatewayConfig-f3a53f657ea324f7
Draft

[test] Add tests for config.validateGatewayConfig and validateTrustedBots#3637
github-actions[bot] wants to merge 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>
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.

0 participants