mirror of https://github.com/status-im/consul.git
sdk/freeport: rename Port to GetOne
For better consistency with GetN
This commit is contained in:
parent
ba41db5c4e
commit
4185045a7f
|
@ -308,7 +308,7 @@ func TestAgent_HTTPMaxHeaderBytes(t *testing.T) {
|
|||
},
|
||||
RuntimeConfig: &config.RuntimeConfig{
|
||||
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,
|
||||
},
|
||||
|
@ -4679,7 +4679,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
port := freeport.Port(t)
|
||||
port := freeport.GetOne(t)
|
||||
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port)
|
||||
|
||||
// Due to some ordering, we'll have to manually configure these ports in
|
||||
|
|
|
@ -143,7 +143,7 @@ func TestOperator_RaftRemovePeerByAddress(t *testing.T) {
|
|||
// Try to remove a peer that's not there.
|
||||
arg := structs.RaftRemovePeerRequest{
|
||||
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{}
|
||||
err := msgpackrpc.CallWithCodec(codec, "Operator.RaftRemovePeerByAddress", &arg, &reply)
|
||||
|
@ -260,7 +260,7 @@ func TestOperator_RaftRemovePeerByID(t *testing.T) {
|
|||
|
||||
// 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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
|
|
@ -717,7 +717,7 @@ func TestServer_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
|
||||
t.Parallel()
|
||||
|
||||
port := freeport.Port(t)
|
||||
port := freeport.GetOne(t)
|
||||
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port)
|
||||
|
||||
dir1, s1 := testServerWithConfig(t, func(c *Config) {
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestNewDialer_WithALPNWrapper(t *testing.T) {
|
|||
|
||||
// Send all of the traffic to dc2's server
|
||||
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.AddStopACMESearch(gwAddr)
|
||||
require.NoError(t, p.Start())
|
||||
|
@ -181,7 +181,7 @@ func TestNewDialer_IntegrationWithTLSEnabledHandler(t *testing.T) {
|
|||
func TestNewDialer_IntegrationWithTLSEnabledHandler_viaMeshGateway(t *testing.T) {
|
||||
// if this test is failing because of expired certificates
|
||||
// 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))
|
||||
registerWithGRPC(t, res)
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestPublicListener(t *testing.T) {
|
|||
testApp := NewTestTCPServer(t)
|
||||
defer testApp.Close()
|
||||
|
||||
port := freeport.Port(t)
|
||||
port := freeport.GetOne(t)
|
||||
cfg := PublicListenerConfig{
|
||||
BindAddress: "127.0.0.1",
|
||||
BindPort: port,
|
||||
|
@ -179,7 +179,7 @@ func TestUpstreamListener(t *testing.T) {
|
|||
DestinationName: "db",
|
||||
Config: map[string]interface{}{"connect_timeout_ms": 100},
|
||||
LocalBindAddress: "localhost",
|
||||
LocalBindPort: freeport.Port(t),
|
||||
LocalBindPort: freeport.GetOne(t),
|
||||
}
|
||||
|
||||
// Setup metrics to test they are recorded
|
||||
|
|
|
@ -109,7 +109,7 @@ func NewTestServer(t testing.T, service string, ca *structs.CARoot) *TestServer
|
|||
CA: ca,
|
||||
stopChan: make(chan struct{}),
|
||||
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{}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ func alloc() (int, net.Listener) {
|
|||
|
||||
// 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) {
|
||||
ports, err := Take(n)
|
||||
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
|
||||
// future.
|
||||
//
|
||||
// Most callers should prefer GetN or Port.
|
||||
// Most callers should prefer GetN or GetOne.
|
||||
func Take(n int) (ports []int, err error) {
|
||||
if n <= 0 {
|
||||
return nil, fmt.Errorf("freeport: cannot take %d ports", n)
|
||||
|
@ -419,10 +419,10 @@ func GetN(t TestingT, n int) []int {
|
|||
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.
|
||||
// Use GetN if more than a single port is required.
|
||||
func Port(t TestingT) int {
|
||||
func GetOne(t TestingT) int {
|
||||
t.Helper()
|
||||
return GetN(t, 1)[0]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue