internal/runtimeconfig: improve test set up of fake server by using port
0 to automatically pick a port.
Change-Id: I6619af41ed18520f1c39256407fa774a660fd513
Reviewed-on: https://go-review.googlesource.com/86076
Reviewed-by: Ross Light <light@google.com>
diff --git a/internal/runtimeconfig/runtimeconfig_test.go b/internal/runtimeconfig/runtimeconfig_test.go
index 35fb3e8..c82dea6 100644
--- a/internal/runtimeconfig/runtimeconfig_test.go
+++ b/internal/runtimeconfig/runtimeconfig_test.go
@@ -48,12 +48,10 @@
}
func setUp(t *testing.T, fs *fakeServer) (*Client, func()) {
- // TODO: Replace logic to use a port picker.
- const address = "localhost:8888"
// Set up gRPC server.
- lis, err := net.Listen("tcp", address)
+ lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
- t.Fatalf("tcp listen on %s failed: %v", address, err)
+ t.Fatalf("tcp listen failed: %v", err)
}
s := grpc.NewServer()
pb.RegisterRuntimeConfigManagerServer(s, fs)
@@ -61,7 +59,7 @@
go s.Serve(lis)
// Set up client.
- conn, err := grpc.Dial(address, grpc.WithInsecure())
+ conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
if err != nil {
t.Fatalf("did not connect: %v", err)
}