Skip to content

test(knative): add unit test suite for KService resource class - #1091

Open
vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:test/kservice-resource-unit-tests
Open

vikash7485 wants to merge 1 commit into
headlamp-k8s:mainfrom
vikash7485:test/kservice-resource-unit-tests

Conversation

@vikash7485

Copy link
Copy Markdown

Description

This PR adds a comprehensive unit test suite for the KService custom resource class (plugins/knative/src/resources/knative/kservice.ts), covering static CRD metadata, route definitions, default base object creation, URL/readiness getters, and autoscaling patch body creation.

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

  1. Static CRD Metadata & Routes: Asserts static properties (kind, apiName, apiVersion, isNamespaced) and route paths (detailsRoute, listRoute).
  2. buildAutoscalingPatch():
    • Returns null when all autoscaling input parameters are undefined.
    • Generates annotations patch for metric, target, minScale, maxScale, targetUtilization, scaleDownDelay, and stableWindow.
    • Generates template spec patch for containerConcurrency.
    • Combines annotations and template spec patches cleanly.
  3. Instance Getters (url & isReady):
    • Correctly reports URL and readiness when status.url and Ready condition are present.
    • Falls back to status.address.url when status.url is missing.
    • Handles missing status fields gracefully (url returns undefined, isReady returns false).
  4. getBaseObject(): Asserts default base object configuration template.

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 (38/38 unit tests passing across 6 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 working on this.

The commit messages could use some tidying up to match our contribution guidelines. We use Linux kernel style — the contributing guide has the details, and git log shows good examples.

Commits that need attention
  • test(knative): add unit test suite for KService resource class — 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

Two autoscaling annotation mappings used by the UI remain untested.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds unit coverage for Knative’s KService resource class.

Changes:

  • Tests metadata, routes, autoscaling patches, status getters, and defaults.
  • Adds Vitest aliases for Headlamp Kubernetes modules.
File Description
knative/​vitest.config.mts Configures test module resolution.
knative/​src/​resources/​knative/​kservice.test.ts Adds the KService unit suite.

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

Comment thread knative/src/resources/knative/kservice.test.ts
Add unit test coverage for the KService resource class including static metadata, routes, autoscaling patches with scale bounds annotations, readiness and URL getters, and default base resource template.

Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
@vikash7485
vikash7485 force-pushed the test/kservice-resource-unit-tests branch from 6c154e1 to 9607ad9 Compare September 30, 2026 17:23
@vikash7485
vikash7485 requested a review from illume September 30, 2026 17:25
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