@@ -246,6 +246,42 @@ func TestResolveUpstreamCluster_WithRef_NoTimeout(t *testing.T) {
246246 assert .Nil (t , timeout , "No timeout in definition should result in nil timeout" )
247247}
248248
249+ // A per-operation ref reuses the referenced upstreamDefinition's cluster and
250+ // inherits that definition's connect timeout. This asserts the timeout flows
251+ // through the per-op resolution path specifically (not just the API-level path).
252+ func TestResolvePerOpDefinitionCluster_InheritsDefinitionTimeout (t * testing.T ) {
253+ translator := & Translator {}
254+ timeoutStr := "45s"
255+ basePath := "/v2"
256+ target := & api.RestAPIOperationUpstreamTarget {Ref : "my-svc" }
257+ definitions := & []api.UpstreamDefinition {
258+ {
259+ Name : "my-svc" ,
260+ BasePath : & basePath ,
261+ Timeout : & api.UpstreamTimeout {
262+ Connect : & timeoutStr ,
263+ },
264+ Upstreams : []struct {
265+ Url string `json:"url" yaml:"url"`
266+ Weight * int `json:"weight,omitempty" yaml:"weight,omitempty"`
267+ }{
268+ {Url : "http://backend-1:9000" },
269+ },
270+ },
271+ }
272+
273+ clusterName , defBasePath , timeout , err := translator .resolvePerOpDefinitionCluster ("RestApi" , "test-api" , target , definitions )
274+
275+ require .NoError (t , err )
276+ assert .Equal (t , constants .UpstreamDefinitionClusterPrefix + "RestApi_test-api_my-svc" , clusterName ,
277+ "per-op route should reuse the upstream-definition cluster" )
278+ assert .Equal (t , "/v2" , defBasePath , "per-op route inherits the definition basePath" )
279+ require .NotNil (t , timeout )
280+ require .NotNil (t , timeout .Connect )
281+ assert .Equal (t , 45 * time .Second , * timeout .Connect ,
282+ "per-op ref must inherit the referenced definition's connect timeout" )
283+ }
284+
249285func TestResolveUpstreamCluster_WithRef_NotFound (t * testing.T ) {
250286 translator := & Translator {}
251287 ref := "0000-non-existent-0000-000000000000"
0 commit comments