Skip to content

test(knative): add unit test coverage for isKnativeInstalled helper - #1075

Open
vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:test/is-knative-installed-unit-tests
Open

vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:test/is-knative-installed-unit-tests

Conversation

@vikash7485

Copy link
Copy Markdown

Description

This PR adds a comprehensive unit test suite for the isKnativeInstalled helper function (plugins/knative/src/isKnativeInstalled.ts), which determines whether Knative CRDs exist on selected cluster(s) to conditionally display or hide Knative navigation in Headlamp.

Prior to this PR, isKnativeInstalled.ts had zero test coverage.

Covered Test Scenarios (plugins/knative/src/isKnativeInstalled.test.ts):

  1. Empty / Invalid Inputs: Returns false when clusters is an empty array, null, or undefined.
  2. Single Cluster (Installed): Returns true when the services.serving.knative.dev CRD exists in a single cluster.
  3. Single Cluster (Missing): Returns false when the Knative CRD is not found in the cluster.
  4. Multi-Cluster (All Installed): Returns true when Knative CRDs exist across all selected clusters in a multi-cluster setup.
  5. Multi-Cluster (Partial Installation): Returns false when Knative CRDs are missing in at least one cluster in a multi-cluster setup.
  6. Network Rejection Handling: Handles API call failures/rejections gracefully and returns false.

How Has This Been Tested?

  • TypeScript Type Checking: Verified compilation with npx tsc --noEmit (0 errors).
  • ESLint / Formatting: Verified formatting rules pass cleanly (npx eslint).
  • Unit Testing: Executed npx vitest run (All 28 unit tests passing across 5 test files).

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes.

Can you please have a look at the git commits to see if they meet the contribution guidelines? We use a Linux kernel style of git commits. See the contributing guide for general context, and please see previous git commits with git log for examples.

Commits that need attention
  • test(knative): add unit test coverage for isKnativeInstalled helper — Missing area: description prefix — e.g. frontend: HomeButton: Fix so it navigates to home or backend: config: Add enable-dynamic-clusters flag.
Commit guidelines
  • Use atomic commits focused on a single change.
  • Use the title format <area>: <Description of changes> — description must start with a capital letter.
  • Keep the title under 72 characters (soft requirement).
  • Explain the intention and why the change is needed.
  • Make commit titles meaningful and describe what changed.
  • Do not add code that a later commit rewrites; squash or reorder commits instead.
  • Do not include Fixes #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The tests do not verify the CRD name and cluster arguments central to the helper’s behavior.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Adds unit coverage for Knative installation detection across empty, single-cluster, multi-cluster, missing-CRD, and rejected-request scenarios.

Changes:

  • Mocks CRD API responses.
  • Tests successful and failed installation checks.
File Description
knative/​src/​isKnativeInstalled.test.ts Adds tests for isKnativeInstalled.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread knative/src/isKnativeInstalled.test.ts
Comment thread knative/src/isKnativeInstalled.test.ts Outdated
Add unit tests for isKnativeInstalled helper covering single cluster, multi-cluster, missing CRD, and request error cases, with apiGet argument assertions.

Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
@vikash7485
vikash7485 force-pushed the test/is-knative-installed-unit-tests branch from a548555 to fefe62c Compare September 30, 2026 17:01
@vikash7485
vikash7485 requested a review from illume September 30, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants