@@ -128,21 +128,64 @@ configurations:
128128 & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {IdleConnTimeout : dur ("-5m" )}}),
129129 )
130130
131- It ("allows -1 tcpKeepAlive to disable keep-alive probes" , func () {
131+ It ("allows negative tcpKeepAlive to disable keep-alive probes" , func () {
132132 ctx := cpi .New ()
133133 cfg := & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPKeepAlive : dur ("-1s" )}}
134134 Expect (cfg .ApplyTo (ctx .ConfigContext (), ctx )).To (Succeed ())
135135 g := MustGetHTTPSettings (ctx )
136136 Expect (g .TCPKeepAlive .TimeDuration ()).To (HaveValue (Equal (- 1 * time .Second )))
137137 })
138138
139- It ("rejects tcpKeepAlive values more negative than -1" , func () {
140- ctx := cpi .New ()
141- cfg := & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPKeepAlive : dur ("-2s" )}}
142- Expect (cfg .ApplyTo (ctx .ConfigContext (), ctx )).To (MatchError (
143- ContainSubstring ("invalid value for tcpKeepAlive" ),
144- ))
145- })
139+ DescribeTable ("accepts compound duration like 1h5s" ,
140+ func (cfg * config.HTTPConfig ) {
141+ ctx := cpi .New ()
142+ Expect (cfg .ApplyTo (ctx .ConfigContext (), ctx )).To (Succeed ())
143+ },
144+ Entry ("timeout" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {Timeout : dur ("1h5s" )}}),
145+ Entry ("tcpDialTimeout" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPDialTimeout : dur ("1h5s" )}}),
146+ Entry ("tcpKeepAlive" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPKeepAlive : dur ("1h5s" )}}),
147+ Entry ("tlsHandshakeTimeout" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TLSHandshakeTimeout : dur ("1h5s" )}}),
148+ Entry ("responseHeaderTimeout" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {ResponseHeaderTimeout : dur ("1h5s" )}}),
149+ Entry ("idleConnTimeout" , & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {IdleConnTimeout : dur ("1h5s" )}}),
150+ )
151+
152+ DescribeTable ("rejects negative compound duration -10h5m" ,
153+ func (field string , cfg * config.HTTPConfig ) {
154+ ctx := cpi .New ()
155+ Expect (cfg .ApplyTo (ctx .ConfigContext (), ctx )).To (MatchError (
156+ ContainSubstring ("invalid value for " + field ),
157+ ))
158+ },
159+ Entry ("timeout" , "timeout" ,
160+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {Timeout : dur ("-10h5m" )}}),
161+ Entry ("tcpDialTimeout" , "tcpDialTimeout" ,
162+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPDialTimeout : dur ("-10h5m" )}}),
163+ Entry ("tlsHandshakeTimeout" , "tlsHandshakeTimeout" ,
164+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TLSHandshakeTimeout : dur ("-10h5m" )}}),
165+ Entry ("responseHeaderTimeout" , "responseHeaderTimeout" ,
166+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {ResponseHeaderTimeout : dur ("-10h5m" )}}),
167+ Entry ("idleConnTimeout" , "idleConnTimeout" ,
168+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {IdleConnTimeout : dur ("-10h5m" )}}),
169+ )
170+
171+ DescribeTable ("rejects -10s" ,
172+ func (field string , cfg * config.HTTPConfig ) {
173+ ctx := cpi .New ()
174+ Expect (cfg .ApplyTo (ctx .ConfigContext (), ctx )).To (MatchError (
175+ ContainSubstring ("invalid value for " + field ),
176+ ))
177+ },
178+ Entry ("timeout" , "timeout" ,
179+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {Timeout : dur ("-10s" )}}),
180+ Entry ("tcpDialTimeout" , "tcpDialTimeout" ,
181+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TCPDialTimeout : dur ("-10s" )}}),
182+ Entry ("tlsHandshakeTimeout" , "tlsHandshakeTimeout" ,
183+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {TLSHandshakeTimeout : dur ("-10s" )}}),
184+ Entry ("responseHeaderTimeout" , "responseHeaderTimeout" ,
185+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {ResponseHeaderTimeout : dur ("-10s" )}}),
186+ Entry ("idleConnTimeout" , "idleConnTimeout" ,
187+ & config.HTTPConfig {HTTPSettings : cpi.HTTPSettings {IdleConnTimeout : dur ("-10s" )}}),
188+ )
146189
147190 It ("default settings are nil" , func () {
148191 g := MustGetHTTPSettings (cpi .New ())
0 commit comments