test(cmd/server): cover option wiring with extracted helpers#325
Merged
Conversation
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>
b6e231a to
3b94b1e
Compare
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.
Summary
The functional-options refactors (PR #235 server, #236 audit/auth, #249 config/adminclient, #254 schema) made every constructor in
cmd/server/main.gotake a list ofWith...()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) serverOptionsBuildbuildGatewayOptions(cfg, logger, openAPISpec, gwTLS) gatewayOptionsBuildEach 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_TLS—InsecureListen=false⇒ TLS option appended,UseTLSsetTestBuildServerOptions_Insecure—InsecureListen=true⇒ Insecure option appended,UseInsecuresetTestBuildServerOptions_RateLimiterWired— non-nil interceptor ⇒WithRateLimiterappended,HasRateLimitersetTestBuildServerOptions_RateLimiterAbsent— nil interceptor ⇒ noWithRateLimiterTestBuildServerOptions_ExtraGRPCOpts— extragrpc.ServerOptions fold into a singleWithGRPCServerOptionsTestBuildGatewayOptions_TLS/TestBuildGatewayOptions_Insecure— same TLS/Insecure splitWhy decisions instead of inspecting options
server.Optionis an opaque closure (func(*Config)). Inspecting it from outside theserverpackage would require either reflection or exporting the internalConfig— 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 greengo test -v -run TestBuild ./cmd/server/— 7/7 pass🤖 Generated with Claude Code