Skip to content

Commit 314dd81

Browse files
committed
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 <[email protected]>
1 parent 87b8f97 commit 314dd81

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

tests/cmd/pidfd-kill/pidfd-kill.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ func recvPidfd(socketFile string) (*os.File, error) {
9999
}
100100
defer conn.Close()
101101

102-
unixconn, ok := conn.(*net.UnixConn)
103-
if !ok {
104-
return nil, errors.New("failed to cast to unixconn")
105-
}
106-
107-
socket, err := unixconn.File()
102+
socket, err := conn.(*net.UnixConn).File()
108103
if err != nil {
109104
return nil, err
110105
}

tests/cmd/recvtty/recvtty.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,7 @@ func handleSingle(path string, noStdin bool) error {
8585
// Close ln, to allow for other instances to take over.
8686
ln.Close()
8787

88-
// Get the fd of the connection.
89-
unixconn, ok := conn.(*net.UnixConn)
90-
if !ok {
91-
return errors.New("failed to cast to unixconn")
92-
}
93-
94-
socket, err := unixconn.File()
88+
socket, err := conn.(*net.UnixConn).File()
9589
if err != nil {
9690
return err
9791
}
@@ -158,13 +152,7 @@ func handleNull(path string) error {
158152
// Don't leave references lying around.
159153
defer conn.Close()
160154

161-
// Get the fd of the connection.
162-
unixconn, ok := conn.(*net.UnixConn)
163-
if !ok {
164-
return
165-
}
166-
167-
socket, err := unixconn.File()
155+
socket, err := conn.(*net.UnixConn).File()
168156
if err != nil {
169157
return
170158
}

0 commit comments

Comments
 (0)