package controlplane

import (
	"fmt"
	"net"

	"go.uber.org/zap"
)

// noopLogger returns a no-op zap logger suitable for tests.
func noopLogger() *zap.Logger {
	return zap.NewNop()
}

// tcpPortStr converts an int to a string port for use with net.JoinHostPort.
func tcpPortStr(port int) string {
	return fmt.Sprintf("%d", port)
}

// freeTCPPort returns a free TCP port on 127.0.0.1.
func freeTCPPort() (int, error) {
	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		return 0, err
	}
	defer ln.Close()
	return ln.Addr().(*net.TCPAddr).Port, nil
}
