Skip to content

test(knative): add unit test suite for KRevision resource class - #1100

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

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

Conversation

@vikash7485

Copy link
Copy Markdown

Description

This PR adds a comprehensive unit test suite for the KRevision custom resource class (plugins/knative/src/resources/knative/revision.ts), which handles Knative Revision resource parsing, condition status evaluation, and traffic split target calculation.

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

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

  1. Static CRD Metadata & Routes: Asserts static properties (kind, apiName, apiVersion, isNamespaced) and route paths (detailsRoute, listRoute).
  2. Readiness Getters (isReady & readyCondition):
    • Correctly evaluates readiness when Ready condition is True.
    • Returns false when Ready condition status is False or missing.
  3. Parent Service Label (parentService):
    • Extracts service name from serving.knative.dev/service metadata label.
    • Returns undefined when label is omitted.
  4. Container Specs (containers & primaryImage):
    • Parses container list and primary container image (containers[0].image).
    • Returns empty array and undefined when spec is empty.
  5. Traffic Target Split (getTrafficInService):
    • Returns empty array when kservice is null.
    • Filters traffic split targets matching exact revisionName.
    • Matches latestRevision targets when latestReadyRevisionName equals the revision name.

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 43 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 the contribution.

Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.

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

🟢 Approval recommended

Coverage matches the implementation; only a minor test-name mismatch remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds unit coverage for the Knative KRevision resource class.

Changes:

  • Tests metadata, routes, readiness, labels, and containers.
  • Tests direct and latest-revision traffic matching.
File Description
knative/​src/​resources/​knative/​revision.test.ts Adds the KRevision unit test 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/revision.test.ts Outdated
Add unit test coverage for the KRevision resource class including static metadata, routes, readiness, parent service label, containers, primary image, and traffic resolution in service.

Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
@vikash7485
vikash7485 force-pushed the test/krevision-resource-unit-tests branch from 9532603 to 9768db1 Compare September 30, 2026 17:30
@vikash7485
vikash7485 requested a review from illume September 30, 2026 17:33
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