Skip to content

test(cmd/server): cover option wiring with extracted helpers#325

Merged
zeevdr merged 4 commits into
mainfrom
test/284-main-option-wiring
May 1, 2026
Merged

test(cmd/server): cover option wiring with extracted helpers#325
zeevdr merged 4 commits into
mainfrom
test/284-main-option-wiring

Conversation

@zeevdr
Copy link
Copy Markdown
Member

@zeevdr zeevdr commented May 1, 2026

Summary

The functional-options refactors (PR #235 server, #236 audit/auth, #249 config/adminclient, #254 schema) made every constructor in cmd/server/main.go take a list of With...() options derived from env vars and cfg flags. None of that wiring was tested, so the bug class "flag is read but never wired into an option" was silent.

This extracts the server + gateway option-construction logic into pure helpers:

  • buildServerOptions(cfg, logger, extraGRPCOpts, serverTLS, rl) serverOptionsBuild
  • buildGatewayOptions(cfg, logger, openAPISpec, gwTLS) gatewayOptionsBuild

Each helper returns both the option slice and a small struct describing the boolean decisions (UseTLS, UseInsecure, HasRateLimiter). Tests assert on the decisions, catching the silent-default bug class without inspecting opaque option closures.

Test cases

  • TestBuildServerOptions_TLSInsecureListen=false ⇒ TLS option appended, UseTLS set
  • TestBuildServerOptions_InsecureInsecureListen=true ⇒ Insecure option appended, UseInsecure set
  • TestBuildServerOptions_RateLimiterWired — non-nil interceptor ⇒ WithRateLimiter appended, HasRateLimiter set
  • TestBuildServerOptions_RateLimiterAbsent — nil interceptor ⇒ no WithRateLimiter
  • TestBuildServerOptions_ExtraGRPCOpts — extra grpc.ServerOptions fold into a single WithGRPCServerOptions
  • TestBuildGatewayOptions_TLS / TestBuildGatewayOptions_Insecure — same TLS/Insecure split

Why decisions instead of inspecting options

server.Option is an opaque closure (func(*Config)). Inspecting it from outside the server package would require either reflection or exporting the internal Config — both worse than the current approach. Returning a struct of decisions keeps the helper pure, the tests strict, and the production wiring trivial.

Closes #284

Test plan

  • make test — full suite green
  • go test -v -run TestBuild ./cmd/server/ — 7/7 pass
  • CI green

🤖 Generated with Claude Code

The functional-options refactors (PR #235 server, #236 audit/auth, #249
config/adminclient, #254 schema) made every constructor in cmd/server/main.go
take a list of With...() options derived from env vars + cfg flags. The
wiring had no tests, so the bug class "flag is read but never wired into
an option" was silent.

Extract the server + gateway option-construction logic into pure helpers
(buildServerOptions, buildGatewayOptions) that return both the option
slice and a small struct describing the boolean decisions (UseTLS,
UseInsecure, HasRateLimiter). Tests assert on the decisions, catching
the silent-default bug class without inspecting opaque option closures.

Cases covered: TLS vs Insecure (server + gateway); rate limiter wired
when non-nil and absent when nil; extra grpc.ServerOptions are folded
into a single WithGRPCServerOptions and don't inflate the option slice.

Closes #284

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@zeevdr zeevdr force-pushed the test/284-main-option-wiring branch from b6e231a to 3b94b1e Compare May 1, 2026 05:45
@zeevdr zeevdr merged commit b76aec5 into main May 1, 2026
18 checks passed
@zeevdr zeevdr deleted the test/284-main-option-wiring branch May 1, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for cmd/server/main.go option wiring

1 participant