@@ -22,28 +22,49 @@ import (
22
22
"errors"
23
23
"fmt"
24
24
"io"
25
+ "math"
25
26
"net"
26
27
"reflect"
27
28
"testing"
28
29
"time"
29
30
)
30
31
31
- func (s ) TestTimeoutDecode (t * testing.T ) {
32
+ func (s ) TestDecodeTimeout (t * testing.T ) {
32
33
for _ , test := range []struct {
33
34
// input
34
35
s string
35
36
// output
36
- d time.Duration
37
- err error
37
+ d time.Duration
38
+ wantErr bool
38
39
}{
39
- {"1234S" , time .Second * 1234 , nil },
40
- {"1234x" , 0 , fmt .Errorf ("transport: timeout unit is not recognized: %q" , "1234x" )},
41
- {"1" , 0 , fmt .Errorf ("transport: timeout string is too short: %q" , "1" )},
42
- {"" , 0 , fmt .Errorf ("transport: timeout string is too short: %q" , "" )},
40
+
41
+ {"00000001n" , time .Nanosecond , false },
42
+ {"10u" , time .Microsecond * 10 , false },
43
+ {"00000010m" , time .Millisecond * 10 , false },
44
+ {"1234S" , time .Second * 1234 , false },
45
+ {"00000001M" , time .Minute , false },
46
+ {"09999999S" , time .Second * 9999999 , false },
47
+ {"99999999S" , time .Second * 99999999 , false },
48
+ {"99999999M" , time .Minute * 99999999 , false },
49
+ {"2562047H" , time .Hour * 2562047 , false },
50
+ {"2562048H" , time .Duration (math .MaxInt64 ), false },
51
+ {"99999999H" , time .Duration (math .MaxInt64 ), false },
52
+ {"-1S" , 0 , true },
53
+ {"1234x" , 0 , true },
54
+ {"1234s" , 0 , true },
55
+ {"1234" , 0 , true },
56
+ {"1" , 0 , true },
57
+ {"" , 0 , true },
58
+ {"9a1S" , 0 , true },
59
+ {"0S" , 0 , true }, // PROTOCOL-HTTP2.md requires positive integers
60
+ {"00000000S" , 0 , true },
61
+ {"000000000S" , 0 , true },
43
62
} {
44
63
d , err := decodeTimeout (test .s )
45
- if d != test .d || fmt .Sprint (err ) != fmt .Sprint (test .err ) {
46
- t .Fatalf ("timeoutDecode(%q) = %d, %v, want %d, %v" , test .s , int64 (d ), err , int64 (test .d ), test .err )
64
+ gotErr := err != nil
65
+ if d != test .d || gotErr != test .wantErr {
66
+ t .Errorf ("timeoutDecode(%q) = %d, %v, want %d, wantErr=%v" ,
67
+ test .s , int64 (d ), err , int64 (test .d ), test .wantErr )
47
68
}
48
69
}
49
70
}
0 commit comments