-
Notifications
You must be signed in to change notification settings - Fork 134
Allow dots and forbid slashes in new xDS resource IDs #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
webapp/tests/dogma/features/xds/K8sAggregatorEditor.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /* | ||
| * Copyright 2026 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { renderWithProviders } from 'dogma/util/test-utils'; | ||
| import { K8sAggregatorEditor } from 'dogma/features/xds/K8sAggregatorEditor'; | ||
| import * as xdsApiSlice from 'dogma/features/xds/xdsApiSlice'; | ||
|
|
||
| jest.mock('next/router', () => ({ | ||
| __esModule: true, | ||
| default: { push: jest.fn() }, | ||
| })); | ||
|
|
||
| jest.mock('dogma/features/xds/useGroupWriteAccess', () => ({ | ||
| useGroupWriteAccess: () => ({ hasWrite: true, isLoading: false }), | ||
| })); | ||
|
|
||
| // Stub out the status panel and preview modal — they make additional API calls unrelated to ID validation. | ||
| jest.mock('dogma/features/xds/K8sAggregatorStatus', () => ({ | ||
| K8sAggregatorStatus: () => null, | ||
| })); | ||
| jest.mock('dogma/features/xds/K8sAggregatorPreviewModal', () => ({ | ||
| K8sAggregatorPreviewModal: () => null, | ||
| })); | ||
|
|
||
| // chakra-react-select does not work in JSDOM; replace with a plain <select>. | ||
| jest.mock('chakra-react-select', () => ({ | ||
| Select: ({ name, options, onChange, value, placeholder }: any) => ( | ||
| <select | ||
| name={name} | ||
| value={value?.value || ''} | ||
| onChange={(e) => { | ||
| const selected = options?.find((o: any) => o.value === e.target.value); | ||
| onChange(selected ?? null); | ||
| }} | ||
| > | ||
| <option value="">{placeholder}</option> | ||
| {options?.map((o: any) => ( | ||
| <option key={o.value} value={o.value}> | ||
| {o.label} | ||
| </option> | ||
| ))} | ||
| </select> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('dogma/features/xds/xdsApiSlice', () => ({ | ||
| // Preserve reducerPath and reducer so the Redux store initialises correctly. | ||
| ...jest.requireActual('dogma/features/xds/xdsApiSlice'), | ||
| useCreateK8sAggregatorMutation: jest.fn(), | ||
| useUpdateK8sAggregatorMutation: jest.fn(), | ||
| useDeleteK8sAggregatorMutation: jest.fn(), | ||
| usePreviewK8sAggregatorMutation: jest.fn(), | ||
| useGetK8sAggregatorQuery: jest.fn(), | ||
| useListCredentialsQuery: jest.fn(), | ||
| })); | ||
|
|
||
| // Minimal aggregator body with one fully-populated watcher, satisfying all required watcher fields. | ||
| const VALID_WATCHER_CONTENT = { | ||
| localityLbEndpoints: [ | ||
| { | ||
| watcher: { | ||
| serviceName: 'my-service', | ||
| kubeconfig: { controlPlaneUrl: 'https://kubernetes.default.svc' }, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| describe('K8sAggregatorEditor – aggregator ID pattern validation', () => { | ||
| let mockCreate: jest.Mock; | ||
| let mockUpdate: jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| mockCreate = jest.fn().mockReturnValue({ unwrap: () => Promise.resolve({}) }); | ||
| mockUpdate = jest.fn().mockReturnValue({ unwrap: () => Promise.resolve({}) }); | ||
|
|
||
| jest | ||
| .mocked(xdsApiSlice.useCreateK8sAggregatorMutation) | ||
| .mockReturnValue([mockCreate, { isLoading: false }] as any); | ||
| jest | ||
| .mocked(xdsApiSlice.useUpdateK8sAggregatorMutation) | ||
| .mockReturnValue([mockUpdate, { isLoading: false }] as any); | ||
| jest | ||
| .mocked(xdsApiSlice.useDeleteK8sAggregatorMutation) | ||
| .mockReturnValue([jest.fn(), { isLoading: false }] as any); | ||
| jest | ||
| .mocked(xdsApiSlice.usePreviewK8sAggregatorMutation) | ||
| .mockReturnValue([jest.fn(), { isLoading: false }] as any); | ||
| jest.mocked(xdsApiSlice.useGetK8sAggregatorQuery).mockReturnValue({ | ||
| data: { content: VALID_WATCHER_CONTENT }, | ||
| isLoading: false, | ||
| error: undefined, | ||
| } as any); | ||
| jest.mocked(xdsApiSlice.useListCredentialsQuery).mockReturnValue({ data: [], error: null } as any); | ||
| }); | ||
|
|
||
| describe('new aggregator', () => { | ||
| it('rejects a slash ID and shows a validation error', async () => { | ||
| const user = userEvent.setup(); | ||
| renderWithProviders(<K8sAggregatorEditor group="foo" isNew />); | ||
|
|
||
| await user.type(screen.getByPlaceholderText('e.g. my-service'), 'foo/bar'); | ||
| await user.click(screen.getByRole('button', { name: /^create$/i })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(/dots allowed, slashes not allowed/i)).toBeInTheDocument(); | ||
| }); | ||
| expect(mockCreate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('accepts a dot ID and calls createAggregator', async () => { | ||
| const user = userEvent.setup(); | ||
| renderWithProviders(<K8sAggregatorEditor group="foo" isNew />); | ||
|
|
||
| await user.type(screen.getByPlaceholderText('e.g. my-service'), 'foo.bar'); | ||
| // Fill the required watcher fields so form submission proceeds past required validation. | ||
| await user.type(screen.getByPlaceholderText('k8s service name'), 'my-service'); | ||
| await user.type(screen.getByPlaceholderText('https://kubernetes.default.svc'), 'https://k8s.default.svc'); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /^create$/i })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockCreate).toHaveBeenCalled(); | ||
| }); | ||
| expect(screen.queryByText(/dots allowed, slashes not allowed/i)).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('existing aggregator with a legacy slash ID', () => { | ||
| it('saves without showing a pattern error (backward compat)', async () => { | ||
| const user = userEvent.setup(); | ||
| renderWithProviders(<K8sAggregatorEditor group="foo" id="foo/bar" isNew={false} />); | ||
|
|
||
| // Wait for the form to be populated from the fetched data. | ||
| await waitFor(() => { | ||
| expect(screen.getByDisplayValue('foo/bar')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /^edit$/i })); | ||
| await user.click(screen.getByRole('button', { name: /^save$/i })); | ||
|
|
||
| // The update should proceed — the slash ID must not be blocked by the pattern. | ||
| await waitFor(() => { | ||
| expect(mockUpdate).toHaveBeenCalled(); | ||
| }); | ||
| expect(screen.queryByText(/dots allowed, slashes not allowed/i)).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.