sdk/freeport: rename Port to GetOne

For better consistency with GetN
This commit is contained in:
Daniel Nephin 2021-11-30 17:32:41 -05:00
parent 11cdf7dfd9
commit 056a52ba64
7 changed files with 14 additions and 14 deletions

View File

@ -308,7 +308,7 @@ func TestAgent_HTTPMaxHeaderBytes(t *testing.T) {
}, },
RuntimeConfig: &config.RuntimeConfig{ RuntimeConfig: &config.RuntimeConfig{
HTTPAddrs: []net.Addr{ HTTPAddrs: []net.Addr{
&net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: freeport.Port(t)}, &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: freeport.GetOne(t)},
}, },
HTTPMaxHeaderBytes: tt.maxHeaderBytes, HTTPMaxHeaderBytes: tt.maxHeaderBytes,
}, },
@ -4679,7 +4679,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
t.Parallel() t.Parallel()
port := freeport.Port(t) port := freeport.GetOne(t)
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port) gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port)
// Due to some ordering, we'll have to manually configure these ports in // Due to some ordering, we'll have to manually configure these ports in

View File

@ -143,7 +143,7 @@ func TestOperator_RaftRemovePeerByAddress(t *testing.T) {
// Try to remove a peer that's not there. // Try to remove a peer that's not there.
arg := structs.RaftRemovePeerRequest{ arg := structs.RaftRemovePeerRequest{
Datacenter: "dc1", Datacenter: "dc1",
Address: raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.Port(t))), Address: raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t))),
} }
var reply struct{} var reply struct{}
err := msgpackrpc.CallWithCodec(codec, "Operator.RaftRemovePeerByAddress", &arg, &reply) err := msgpackrpc.CallWithCodec(codec, "Operator.RaftRemovePeerByAddress", &arg, &reply)
@ -260,7 +260,7 @@ func TestOperator_RaftRemovePeerByID(t *testing.T) {
// Add it manually to Raft. // Add it manually to Raft.
{ {
future := s1.raft.AddVoter(arg.ID, raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.Port(t))), 0, 0) future := s1.raft.AddVoter(arg.ID, raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t))), 0, 0)
if err := future.Error(); err != nil { if err := future.Error(); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }

View File

@ -717,7 +717,7 @@ func TestServer_JoinWAN_viaMeshGateway(t *testing.T) {
t.Parallel() t.Parallel()
port := freeport.Port(t) port := freeport.GetOne(t)
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port) gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port)
dir1, s1 := testServerWithConfig(t, func(c *Config) { dir1, s1 := testServerWithConfig(t, func(c *Config) {

View File

@ -74,7 +74,7 @@ func TestNewDialer_WithALPNWrapper(t *testing.T) {
// Send all of the traffic to dc2's server // Send all of the traffic to dc2's server
var p tcpproxy.Proxy var p tcpproxy.Proxy
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", freeport.Port(t)) gwAddr := ipaddr.FormatAddressPort("127.0.0.1", freeport.GetOne(t))
p.AddRoute(gwAddr, tcpproxy.To(lis2.Addr().String())) p.AddRoute(gwAddr, tcpproxy.To(lis2.Addr().String()))
p.AddStopACMESearch(gwAddr) p.AddStopACMESearch(gwAddr)
require.NoError(t, p.Start()) require.NoError(t, p.Start())
@ -181,7 +181,7 @@ func TestNewDialer_IntegrationWithTLSEnabledHandler(t *testing.T) {
func TestNewDialer_IntegrationWithTLSEnabledHandler_viaMeshGateway(t *testing.T) { func TestNewDialer_IntegrationWithTLSEnabledHandler_viaMeshGateway(t *testing.T) {
// if this test is failing because of expired certificates // if this test is failing because of expired certificates
// use the procedure in test/CA-GENERATION.md // use the procedure in test/CA-GENERATION.md
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", freeport.Port(t)) gwAddr := ipaddr.FormatAddressPort("127.0.0.1", freeport.GetOne(t))
res := resolver.NewServerResolverBuilder(newConfig(t)) res := resolver.NewServerResolverBuilder(newConfig(t))
registerWithGRPC(t, res) registerWithGRPC(t, res)

View File

@ -115,7 +115,7 @@ func TestPublicListener(t *testing.T) {
testApp := NewTestTCPServer(t) testApp := NewTestTCPServer(t)
defer testApp.Close() defer testApp.Close()
port := freeport.Port(t) port := freeport.GetOne(t)
cfg := PublicListenerConfig{ cfg := PublicListenerConfig{
BindAddress: "127.0.0.1", BindAddress: "127.0.0.1",
BindPort: port, BindPort: port,
@ -179,7 +179,7 @@ func TestUpstreamListener(t *testing.T) {
DestinationName: "db", DestinationName: "db",
Config: map[string]interface{}{"connect_timeout_ms": 100}, Config: map[string]interface{}{"connect_timeout_ms": 100},
LocalBindAddress: "localhost", LocalBindAddress: "localhost",
LocalBindPort: freeport.Port(t), LocalBindPort: freeport.GetOne(t),
} }
// Setup metrics to test they are recorded // Setup metrics to test they are recorded

View File

@ -109,7 +109,7 @@ func NewTestServer(t testing.T, service string, ca *structs.CARoot) *TestServer
CA: ca, CA: ca,
stopChan: make(chan struct{}), stopChan: make(chan struct{}),
TLSCfg: TestTLSConfig(t, service, ca), TLSCfg: TestTLSConfig(t, service, ca),
Addr: fmt.Sprintf("127.0.0.1:%d", freeport.Port(t)), Addr: fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t)),
Listening: make(chan struct{}), Listening: make(chan struct{}),
} }
} }

View File

@ -261,7 +261,7 @@ func alloc() (int, net.Listener) {
// MustTake is the same as Take except it panics on error. // MustTake is the same as Take except it panics on error.
// //
// Deprecated: Use GetN or Port instead. // Deprecated: Use GetN or GetOne instead.
func MustTake(n int) (ports []int) { func MustTake(n int) (ports []int) {
ports, err := Take(n) ports, err := Take(n)
if err != nil { if err != nil {
@ -275,7 +275,7 @@ func MustTake(n int) (ports []int) {
// 127.0.0.1 TCP but there is no guarantee that they will remain free in the // 127.0.0.1 TCP but there is no guarantee that they will remain free in the
// future. // future.
// //
// Most callers should prefer GetN or Port. // Most callers should prefer GetN or GetOne.
func Take(n int) (ports []int, err error) { func Take(n int) (ports []int, err error) {
if n <= 0 { if n <= 0 {
return nil, fmt.Errorf("freeport: cannot take %d ports", n) return nil, fmt.Errorf("freeport: cannot take %d ports", n)
@ -419,10 +419,10 @@ func GetN(t TestingT, n int) []int {
return ports return ports
} }
// Port returns a single free port from the reserved port block, and returns the // GetOne returns a single free port from the reserved port block, and returns the
// port to the pool when the test ends. See Take for more details. // port to the pool when the test ends. See Take for more details.
// Use GetN if more than a single port is required. // Use GetN if more than a single port is required.
func Port(t TestingT) int { func GetOne(t TestingT) int {
t.Helper() t.Helper()
return GetN(t, 1)[0] return GetN(t, 1)[0]
} }