From afa031e84638979919a16d3261aa68f694b58719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 22:12:38 +0100 Subject: [PATCH] Use net/netip.Addr instead of net.IP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not really shorter, but more a matter of principle... Signed-off-by: Miloslav Trmač --- integration/openshift.go | 2 +- integration/utils.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/integration/openshift.go b/integration/openshift.go index 68d33d13..635d010d 100644 --- a/integration/openshift.go +++ b/integration/openshift.go @@ -154,7 +154,7 @@ func (cluster *openshiftCluster) prepareRegistryConfig(c *check.C) { } // startRegistry starts the OpenShift registry with configPart on port, waits for it to be ready, and returns the process object, or terminates on failure. -func (cluster *openshiftCluster) startRegistryProcess(c *check.C, port int, configPath string) *exec.Cmd { +func (cluster *openshiftCluster) startRegistryProcess(c *check.C, port uint16, configPath string) *exec.Cmd { cmd := cluster.clusterCmd(map[string]string{ "KUBECONFIG": "openshift.local.registry/openshift-registry.kubeconfig", "DOCKER_REGISTRY_URL": fmt.Sprintf("127.0.0.1:%d", port), diff --git a/integration/utils.go b/integration/utils.go index 44fee496..b1b7f7b9 100644 --- a/integration/utils.go +++ b/integration/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "net" + "net/netip" "os" "os/exec" "path/filepath" @@ -105,8 +106,9 @@ func runExecCmdWithInput(c *check.C, cmd *exec.Cmd, input string) { } // isPortOpen returns true iff the specified port on localhost is open. -func isPortOpen(port int) bool { - conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: port}) +func isPortOpen(port uint16) bool { + ap := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), port) + conn, err := net.DialTCP("tcp", nil, net.TCPAddrFromAddrPort(ap)) if err != nil { return false } @@ -118,7 +120,7 @@ func isPortOpen(port int) bool { // The checking can be aborted by sending a value to the terminate channel, which the caller should // always do using // defer func() {terminate <- true}() -func newPortChecker(c *check.C, port int) (portOpen <-chan bool, terminate chan<- bool) { +func newPortChecker(c *check.C, port uint16) (portOpen <-chan bool, terminate chan<- bool) { portOpenBidi := make(chan bool) // Buffered, so that sending a terminate request after the goroutine has exited does not block. terminateBidi := make(chan bool, 1)