Skip to content

Commit

Permalink
fixup: error type checking
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Jan 5, 2022
1 parent c6ed564 commit 0cfb7ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions internal/sshdialer/posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package sshdialer_test

import (
"errors"
"net"
"os"
)
Expand All @@ -18,3 +19,7 @@ func fixupPrivateKeyMod(path string) {
func listen(addr string) (net.Listener, error) {
return net.Listen("unix", addr)
}

func isErrClosed(err error) bool {
return errors.Is(err, net.ErrClosed)
}
4 changes: 2 additions & 2 deletions internal/sshdialer/ssh_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func withSSHAgent(t *testing.T, ag agent.Agent) func() {
}()
err := agent.ServeAgent(ag, conn)
if err != nil {
if !errors.Is(err, net.ErrClosed) {
if !isErrClosed(err) {
fmt.Fprintf(os.Stderr, "agent.ServeAgent() failed: %v\n", err)
}
}
Expand All @@ -827,7 +827,7 @@ func withSSHAgent(t *testing.T, ag agent.Agent) func() {

err = <-errChan

if !errors.Is(err, net.ErrClosed) {
if !isErrClosed(err) {
t.Fatal(err)
}
cancel()
Expand Down
5 changes: 5 additions & 0 deletions internal/sshdialer/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package sshdialer_test

import (
"errors"
"net"
"os/user"
"strings"
Expand Down Expand Up @@ -35,3 +36,7 @@ func listen(addr string) (net.Listener, error) {
}
return net.Listen("unix", addr)
}

func isErrClosed(err error) bool {
return errors.Is(err, net.ErrClosed) || errors.Is(err, npipe.ErrClosed)
}

0 comments on commit 0cfb7ae

Please sign in to comment.