Skip to content

Commit

Permalink
Handle error check to avoid panic if test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosbox authored and rmani committed Feb 24, 2019
1 parent 1f539fb commit f960cad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions toxics/reset_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func addToxicAndWritePayload(t *testing.T, conn net.Conn, proxy *toxiproxy.Proxy
func checkConnectionState(t *testing.T, conn net.Conn) {
tmp := make([]byte, 10)
_, err := conn.Read(tmp)
opErr, _ := err.(*net.OpError)
syscallErr, _ := opErr.Err.(*os.SyscallError)
if !(syscallErr.Err == syscall.ECONNRESET) {
if opErr, ok := err.(*net.OpError); ok {
syscallErr, _ := opErr.Err.(*os.SyscallError)
if !(syscallErr.Err == syscall.ECONNRESET) {
t.Error("Expected: upstream - connection reset by peer. Got:", err)
}
} else {
t.Error("Expected: upstream - connection reset by peer. Got:", err)
}
_, err = conn.Read(tmp)
Expand Down

0 comments on commit f960cad

Please sign in to comment.