Skip to content

test: add coverage for buildSandboxObject and buildSandboxClaimObject#323

Open
HarshitPal25 wants to merge 1 commit into
volcano-sh:mainfrom
HarshitPal25:test/workload-builder-coverage
Open

test: add coverage for buildSandboxObject and buildSandboxClaimObject#323
HarshitPal25 wants to merge 1 commit into
volcano-sh:mainfrom
HarshitPal25:test/workload-builder-coverage

Conversation

@HarshitPal25
Copy link
Copy Markdown
Contributor

Description:
What type of PR is this?

/kind enhancement

What this PR does / why we need it:
Adds two new test functions to improve test coverage for the workload builder package:

  • TestBuildSandboxObject_WorkloadNameLabel: Verifies that WorkloadNameLabelKey is correctly propagated from params.workloadName to the Sandbox object metadata labels.
  • TestBuildSandboxClaimObject: Verifies buildSandboxClaimObject correctly populates all fields including namespace, name, templateRef, session labels, idle timeout annotations, and owner references (covers both with and without owner reference scenarios).

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Add two new test functions:

- TestBuildSandboxObject_WorkloadNameLabel: verifies WorkloadNameLabelKey
  is correctly propagated from params.workloadName to the Sandbox object
  metadata labels. Covers both set and empty workloadName cases.

- TestBuildSandboxClaimObject: verifies SandboxClaim fields are populated
  correctly including namespace, name, templateRef, session labels, idle
  timeout annotations, and owner references. Tests both with and without
  owner reference scenarios.

Signed-off-by: HarshitPal25 <harshit13082006@gmail.com>
Copilot AI review requested due to automatic review settings May 11, 2026 18:44
@volcano-sh-bot volcano-sh-bot added the kind/enhancement New feature or request label May 11, 2026
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes 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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces unit tests for buildSandboxObject and buildSandboxClaimObject to ensure correct metadata and label assignment. Feedback focuses on improving test coverage by adding assertions for missing fields such as SandboxNameLabelKey and full OwnerReference details, as well as recommending the use of dynamic duration strings for better maintainability.

Comment on lines +178 to +189
if claim.Labels[SessionIdLabelKey] != "session-claim-test" {
t.Errorf("expected label %s=session-claim-test, got %q", SessionIdLabelKey, claim.Labels[SessionIdLabelKey])
}
if claim.Annotations[IdleTimeoutAnnotationKey] != "10m0s" {
t.Errorf("expected annotation %s=10m0s, got %q", IdleTimeoutAnnotationKey, claim.Annotations[IdleTimeoutAnnotationKey])
}
if len(claim.OwnerReferences) != 1 {
t.Fatalf("expected 1 owner reference, got %d", len(claim.OwnerReferences))
}
if claim.OwnerReferences[0].Name != "my-ci" {
t.Errorf("expected owner ref name my-ci, got %q", claim.OwnerReferences[0].Name)
}
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.

medium

The test for buildSandboxClaimObject is missing assertions for several fields that are explicitly set by the function, such as the SandboxNameLabelKey label and the full details of the OwnerReference (APIVersion, Kind, and UID). Additionally, using params.idleTimeout.String() is preferred over hardcoded duration strings for better maintainability and consistency with other tests.

		if claim.Labels[SessionIdLabelKey] != "session-claim-test" {
			t.Errorf("expected label %s=session-claim-test, got %q", SessionIdLabelKey, claim.Labels[SessionIdLabelKey])
		}
		if claim.Labels[SandboxNameLabelKey] != "claim-abc" {
			t.Errorf("expected label %s=claim-abc, got %q", SandboxNameLabelKey, claim.Labels[SandboxNameLabelKey])
		}
		if claim.Annotations[IdleTimeoutAnnotationKey] != params.idleTimeout.String() {
			t.Errorf("expected annotation %s=%s, got %q", IdleTimeoutAnnotationKey, params.idleTimeout.String(), claim.Annotations[IdleTimeoutAnnotationKey])
		}
		if len(claim.OwnerReferences) != 1 {
			t.Fatalf("expected 1 owner reference, got %d", len(claim.OwnerReferences))
		}
		ref := claim.OwnerReferences[0]
		if ref.Name != "my-ci" || ref.Kind != "CodeInterpreter" || ref.APIVersion != "runtime.agentcube.volcano.sh/v1alpha1" || ref.UID != "test-uid-123" {
			t.Errorf("unexpected owner reference: %+v", ref)
		}

Comment on lines +202 to +208
if len(claim.OwnerReferences) != 0 {
t.Errorf("expected 0 owner references, got %d", len(claim.OwnerReferences))
}
if claim.Annotations[IdleTimeoutAnnotationKey] != DefaultSandboxIdleTimeout.String() {
t.Errorf("expected default idle timeout annotation %s, got %q",
DefaultSandboxIdleTimeout.String(), claim.Annotations[IdleTimeoutAnnotationKey])
}
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.

medium

The "without owner reference" subtest only verifies the owner references and the idle timeout annotation. It should also verify basic fields like Namespace, Name, TemplateRef, and Labels to ensure the object is correctly constructed in this scenario as well, maintaining the same level of thoroughness as the "with owner reference" subtest.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds unit tests to increase coverage of the Workload Manager’s workload builder helpers, focusing on label propagation and SandboxClaim construction used when provisioning sandboxes for sessions.

Changes:

  • Add a table-driven test ensuring WorkloadNameLabelKey is set on Sandbox metadata labels from buildSandboxParams.workloadName.
  • Add tests covering buildSandboxClaimObject field population, idle timeout annotation behavior (explicit vs default), and owner reference handling.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.72%. Comparing base (524e55e) to head (1a1d535).
⚠️ Report is 41 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
+ Coverage   47.57%   48.72%   +1.15%     
==========================================
  Files          30       30              
  Lines        2819     2855      +36     
==========================================
+ Hits         1341     1391      +50     
+ Misses       1338     1316      -22     
- Partials      140      148       +8     
Flag Coverage Δ
unittests 48.72% <ø> (+1.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

kind/enhancement New feature or request size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants