* [COMPLIANCE] Update Copyright and License Headers * chore: make gen to generate files with copyright headers * chore: update missed copyright headers --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
25 lines
492 B
Go
25 lines
492 B
Go
// Copyright IBM Corp. 2020, 2025
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package testutil
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestFreePort just returns an available free localhost port
|
|
func TestFreePort(t testing.TB) int {
|
|
t.Helper()
|
|
require := require.New(t)
|
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
|
require.NoError(err)
|
|
|
|
l, err := net.ListenTCP("tcp", addr)
|
|
require.NoError(err)
|
|
defer l.Close()
|
|
return l.Addr().(*net.TCPAddr).Port
|
|
}
|