From 314dd812f520b5be5683f6282fb9d67161bc7f40 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 28 Jul 2025 16:57:03 -0700 Subject: [PATCH] tests/cmd: simplify getting net.UnixConn The typecast can't fail, so it doesn't make sense checking for errors here. Signed-off-by: Kir Kolyshkin --- tests/cmd/pidfd-kill/pidfd-kill.go | 7 +------ tests/cmd/recvtty/recvtty.go | 16 ++-------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/tests/cmd/pidfd-kill/pidfd-kill.go b/tests/cmd/pidfd-kill/pidfd-kill.go index ea9a9df8d..764fa883a 100644 --- a/tests/cmd/pidfd-kill/pidfd-kill.go +++ b/tests/cmd/pidfd-kill/pidfd-kill.go @@ -99,12 +99,7 @@ func recvPidfd(socketFile string) (*os.File, error) { } defer conn.Close() - unixconn, ok := conn.(*net.UnixConn) - if !ok { - return nil, errors.New("failed to cast to unixconn") - } - - socket, err := unixconn.File() + socket, err := conn.(*net.UnixConn).File() if err != nil { return nil, err } diff --git a/tests/cmd/recvtty/recvtty.go b/tests/cmd/recvtty/recvtty.go index 2c82665ab..5e5720cc5 100644 --- a/tests/cmd/recvtty/recvtty.go +++ b/tests/cmd/recvtty/recvtty.go @@ -85,13 +85,7 @@ func handleSingle(path string, noStdin bool) error { // Close ln, to allow for other instances to take over. ln.Close() - // Get the fd of the connection. - unixconn, ok := conn.(*net.UnixConn) - if !ok { - return errors.New("failed to cast to unixconn") - } - - socket, err := unixconn.File() + socket, err := conn.(*net.UnixConn).File() if err != nil { return err } @@ -158,13 +152,7 @@ func handleNull(path string) error { // Don't leave references lying around. defer conn.Close() - // Get the fd of the connection. - unixconn, ok := conn.(*net.UnixConn) - if !ok { - return - } - - socket, err := unixconn.File() + socket, err := conn.(*net.UnixConn).File() if err != nil { return }