Skip to content

Commit e6b7b7a

Browse files
test(gateway): cover per-op definition timeout and fix eds-stable IT definition URL
1 parent 4caca38 commit e6b7b7a

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

gateway/gateway-controller/pkg/xds/translator_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
249285
func TestResolveUpstreamCluster_WithRef_NotFound(t *testing.T) {
250286
translator := &Translator{}
251287
ref := "0000-non-existent-0000-000000000000"

gateway/it/features/api-level-eds-stable.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ Feature: API-Level Upstream EDS-Stable Cluster Naming
178178
main: api-level-eds-default.local
179179
upstreamDefinitions:
180180
- name: backend-default
181+
basePath: /api-main
181182
upstreams:
182-
- url: http://sample-backend:9080/api-main
183+
- url: http://sample-backend:9080
183184
upstream:
184185
main:
185186
ref: backend-default

0 commit comments

Comments
 (0)