Skip to content

Commit ba674e1

Browse files
committed
Fix xDS reference links broken when resource id contains slashes
Motivation: `resolveReference()` built the `id` for navigation links by taking only the last path segment of a resource name such as `groups/dx/clusters/centraldogma-oss-mdc/alpha`, producing `alpha` instead of the correct `centraldogma-oss-mdc/alpha`. Modifications: - In `resolveReference()`, replace `segments[segments.length - 1]` with `segments.slice(idStart).join('/')`, where `idStart` skips the resource-type prefix (1 for regular paths, 2 for k8s paths). Result: - Reference links for resource names containing `/` (e.g. `groups/dx/clusters/centraldogma-oss-mdc/alpha`) now navigate to the correct resource.
1 parent e89d1d4 commit ba674e1

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

345 Bytes
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2026 LY Corporation
3+
*
4+
* LY Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
import { resolveReference } from 'dogma/features/xds/xdsReferences';
17+
18+
describe('resolveReference', () => {
19+
const cdsRef = (name: string) => ({ targetType: 'clusters' as const, name });
20+
21+
describe('groups/{group}/{type}/{id} convention', () => {
22+
it('resolves a simple (non-nested) resource id', () => {
23+
const result = resolveReference('current', cdsRef('groups/dx/clusters/my-cluster'));
24+
expect(result).toMatchObject({ group: 'dx', id: 'my-cluster', k8s: false });
25+
});
26+
27+
it('preserves slashes in a multi-segment resource id', () => {
28+
// regression: previously only the last path segment was captured
29+
const result = resolveReference('current', cdsRef('groups/dx/clusters/centraldogma-oss-mdc/alpha'));
30+
expect(result).toMatchObject({ group: 'dx', id: 'centraldogma-oss-mdc/alpha', k8s: false });
31+
});
32+
33+
it('preserves three-segment resource ids', () => {
34+
const result = resolveReference('current', cdsRef('groups/g1/endpoints/a/b/c'));
35+
expect(result).toMatchObject({ group: 'g1', id: 'a/b/c', k8s: false });
36+
});
37+
});
38+
39+
describe('k8s path (groups/{group}/k8s/{type}/{id})', () => {
40+
it('detects k8s flag and strips the k8s+type prefix', () => {
41+
const result = resolveReference('current', {
42+
targetType: 'endpoints',
43+
name: 'groups/g1/k8s/endpoints/my-ep',
44+
});
45+
expect(result).toMatchObject({ group: 'g1', id: 'my-ep', k8s: true });
46+
});
47+
48+
it('preserves slashes in a k8s multi-segment id', () => {
49+
const result = resolveReference('current', {
50+
targetType: 'endpoints',
51+
name: 'groups/g1/k8s/endpoints/ns/my-ep',
52+
});
53+
expect(result).toMatchObject({ group: 'g1', id: 'ns/my-ep', k8s: true });
54+
});
55+
});
56+
57+
describe('bare name fallback', () => {
58+
it('uses current group and raw name when not in groups/ convention', () => {
59+
const result = resolveReference('mygroup', cdsRef('bare-cluster'));
60+
expect(result).toMatchObject({ group: 'mygroup', id: 'bare-cluster', k8s: false });
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)