mirror of
https://github.com/luxfi/rpc.git
synced 2026-10-30 15:19:52 +00:00
Dial/Listen previously hard-switched on "zap" and rejected every other
transport string, so WithTransport("grpc") could never succeed even
when dial_grpc.go was compiled in with -tags=grpc. Route both through
the existing transport registry instead; gRPC's init() already
self-registers under the build tag, ZAP is always present.
Side benefits:
- Default build still pulls zero gRPC code into the binary.
- Misconfigured callers get an actionable error that names the missing
build tag instead of "unknown transport".
- LLM.md documents the opt-in.
- transport_test.go pins both gated and ungated behavior.
29 lines
796 B
Go
29 lines
796 B
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTransportRegistryGatesGRPC(t *testing.T) {
|
|
// Default build must always have ZAP
|
|
if !HasTransport(TransportZAP) {
|
|
t.Fatal("ZAP transport must always be registered")
|
|
}
|
|
// gRPC is only present when built with -tags=grpc
|
|
if HasTransport(TransportGRPC) {
|
|
t.Log("grpc transport present (built with -tags=grpc)")
|
|
} else {
|
|
t.Log("grpc transport absent (default build)")
|
|
// Dialing grpc on default build must return helpful error
|
|
_, err := Dial(context.Background(), "localhost:1234", WithTransport(TransportGRPC))
|
|
if err == nil {
|
|
t.Fatal("expected error when dialing unregistered transport")
|
|
}
|
|
if !strings.Contains(err.Error(), "-tags=grpc") {
|
|
t.Fatalf("error must hint at build tag, got: %v", err)
|
|
}
|
|
}
|
|
}
|