@@ -23,6 +23,7 @@ import (
23
23
"bytes"
24
24
"crypto/tls"
25
25
"fmt"
26
+ "io"
26
27
"io/ioutil"
27
28
"net"
28
29
"net/http"
@@ -1008,3 +1009,65 @@ func TestParseWarningHeaders(t *testing.T) {
1008
1009
})
1009
1010
}
1010
1011
}
1012
+
1013
+ func TestIsProbableEOF (t * testing.T ) {
1014
+ tests := []struct {
1015
+ name string
1016
+ err error
1017
+ expected bool
1018
+ }{
1019
+ {
1020
+ name : "with no error" ,
1021
+ expected : false ,
1022
+ },
1023
+ {
1024
+ name : "with EOF error" ,
1025
+ err : io .EOF ,
1026
+ expected : true ,
1027
+ },
1028
+ {
1029
+ name : "with unexpected EOF error" ,
1030
+ err : io .ErrUnexpectedEOF ,
1031
+ expected : true ,
1032
+ },
1033
+ {
1034
+ name : "with broken connection error" ,
1035
+ err : fmt .Errorf ("http: can't write HTTP request on broken connection" ),
1036
+ expected : true ,
1037
+ },
1038
+ {
1039
+ name : "with server sent GOAWAY error" ,
1040
+ err : fmt .Errorf ("error foo - http2: server sent GOAWAY and closed the connection - error bar" ),
1041
+ expected : true ,
1042
+ },
1043
+ {
1044
+ name : "with connection reset by peer error" ,
1045
+ err : fmt .Errorf ("error foo - connection reset by peer - error bar" ),
1046
+ expected : true ,
1047
+ },
1048
+ {
1049
+ name : "with use of closed network connection error" ,
1050
+ err : fmt .Errorf ("error foo - Use of closed network connection - error bar" ),
1051
+ expected : true ,
1052
+ },
1053
+ {
1054
+ name : "with url error" ,
1055
+ err : & url.Error {
1056
+ Err : io .ErrUnexpectedEOF ,
1057
+ },
1058
+ expected : true ,
1059
+ },
1060
+ {
1061
+ name : "with unrecognized error" ,
1062
+ err : fmt .Errorf ("error foo" ),
1063
+ expected : false ,
1064
+ },
1065
+ }
1066
+
1067
+ for _ , test := range tests {
1068
+ t .Run (test .name , func (t * testing.T ) {
1069
+ actual := IsProbableEOF (test .err )
1070
+ assert .Equal (t , test .expected , actual )
1071
+ })
1072
+ }
1073
+ }
0 commit comments