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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-07-28 16:57:03 -07:00
parent 87b8f974c8
commit 314dd812f5
2 changed files with 3 additions and 20 deletions
+1 -6
View File
@@ -99,12 +99,7 @@ func recvPidfd(socketFile string) (*os.File, error) {
} }
defer conn.Close() defer conn.Close()
unixconn, ok := conn.(*net.UnixConn) socket, err := conn.(*net.UnixConn).File()
if !ok {
return nil, errors.New("failed to cast to unixconn")
}
socket, err := unixconn.File()
if err != nil { if err != nil {
return nil, err return nil, err
} }
+2 -14
View File
@@ -85,13 +85,7 @@ func handleSingle(path string, noStdin bool) error {
// Close ln, to allow for other instances to take over. // Close ln, to allow for other instances to take over.
ln.Close() ln.Close()
// Get the fd of the connection. socket, err := conn.(*net.UnixConn).File()
unixconn, ok := conn.(*net.UnixConn)
if !ok {
return errors.New("failed to cast to unixconn")
}
socket, err := unixconn.File()
if err != nil { if err != nil {
return err return err
} }
@@ -158,13 +152,7 @@ func handleNull(path string) error {
// Don't leave references lying around. // Don't leave references lying around.
defer conn.Close() defer conn.Close()
// Get the fd of the connection. socket, err := conn.(*net.UnixConn).File()
unixconn, ok := conn.(*net.UnixConn)
if !ok {
return
}
socket, err := unixconn.File()
if err != nil { if err != nil {
return return
} }