Skip to content

frontend: test: Fix mocker namespace interpolation#6475

Open
ahmad-kashkoush wants to merge 2 commits into
kubernetes-sigs:mainfrom
ahmad-kashkoush:fix/mocker-namespace-interpolation
Open

frontend: test: Fix mocker namespace interpolation#6475
ahmad-kashkoush wants to merge 2 commits into
kubernetes-sigs:mainfrom
ahmad-kashkoush:fix/mocker-namespace-interpolation

Conversation

@ahmad-kashkoush

Copy link
Copy Markdown

Summary

This PR fixes a silent bug in generateK8sResourceList where {{i}} placeholders
in metadata.namespace were never replaced, and adds unit tests for the function
to prevent regressions.

Related Issue

Fixes #6474

Changes

  • Fixed frontend/src/test/mocker.ts: assigned the .replace() result back so
    {{i}} in metadata.namespace is actually interpolated
  • Added frontend/src/test/mocker.test.ts: 4 unit tests covering {{i}}
    interpolation in metadata.name, {{i}} interpolation in metadata.namespace,
    absence of literal {{i}} in output, and the numResults option

Steps to Test

  1. cd frontend && npx vitest run src/test/mocker.test.ts
  2. Confirm all 4 tests pass
  3. Optionally call generateK8sResourceList with namespace: 'ns-{{i}}' in any
    existing test and verify items now get distinct namespaces (ns-0, ns-1, …)
    instead of the literal ns-{{i}}

Notes for the Reviewer

  • The test file requires two vi.mock calls at the top to break a
    mocker → KubeObject → util → node → KubeObject circular import; without them
    class Node extends KubeObject evaluates while KubeObject is still undefined.
  • No functional changes to any component or runtime path — only the shared test
    helper is affected.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 11, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@kubernetes-prow kubernetes-prow Bot requested review from joaquimrocha and skoeva July 11, 2026 14:35
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @ahmad-kashkoush!

It looks like this is your first PR to kubernetes-sigs/headlamp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/headlamp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 11, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ahmad-kashkoush
Once this PR has been reviewed and has the lgtm label, please assign illume for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 11, 2026
@ahmad-kashkoush ahmad-kashkoush changed the title Fix/mocker namespace interpolation frontend: test: fix mocker namespace interpolation Jul 11, 2026
@ahmad-kashkoush ahmad-kashkoush force-pushed the fix/mocker-namespace-interpolation branch from c1eb117 to 13b695b Compare July 11, 2026 15:25
@ahmad-kashkoush ahmad-kashkoush changed the title frontend: test: fix mocker namespace interpolation frontend: test: Fix mocker namespace interpolation Jul 11, 2026
@shivamsingh-007

Copy link
Copy Markdown

Nice catch on the missing assignment — .replace()\ returning a new string is an easy one to miss. The tests look thorough (edge cases for literal {{i}},
umResults, namespace interpolation). Also good workaround on the circular dep with the two \�i.mock\ calls. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frontend: mocker: generateK8sResourceList namespace interpolation untested and broken

2 participants