MCPcopy
hub / github.com/smallstep/cli / reservePort

Function reservePort

command/ca/health_test.go:26–39  ·  view source on GitHub ↗

reservePort "reserves" a TCP port by opening a listener on a random port and immediately closing it. The port can then be assumed to be available for running a server on.

(t *testing.T)

Source from the content-addressed store, hash-verified

24// port and immediately closing it. The port can then be assumed to be
25// available for running a server on.
26func reservePort(t *testing.T) (host, port string) {
27 t.Helper()
28 l, err := net.Listen("tcp", ":0")
29 require.NoError(t, err)
30
31 address := l.Addr().String()
32 err = l.Close()
33 require.NoError(t, err)
34
35 host, port, err = net.SplitHostPort(address)
36 require.NoError(t, err)
37
38 return
39}
40
41func Test_healthAction(t *testing.T) {
42 dir := t.TempDir()

Callers 1

Test_healthActionFunction · 0.85

Calls 2

StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…