Skip to content

test: add unit tests for OADP toolset#327

Open
shubham-pampattiwar wants to merge 1 commit into
openshift:mainfrom
shubham-pampattiwar:feature/oadp-toolset-tests
Open

test: add unit tests for OADP toolset#327
shubham-pampattiwar wants to merge 1 commit into
openshift:mainfrom
shubham-pampattiwar:feature/oadp-toolset-tests

Conversation

@shubham-pampattiwar

@shubham-pampattiwar shubham-pampattiwar commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

Adds unit tests for the OADP toolset as requested in #122.

Unit tests (pkg/toolsets/oadp/toolset_test.go)

  • Toolset name, description, no tools, nil resources/resource templates
  • Prompt count, name, arguments, handler presence

Integration tests (pkg/mcp/oadp_test.go)

Following the kubevirt/kiali testing pattern:

  • Toolset registration: no OADP-specific tools exposed, oadp-troubleshoot prompt listed
  • Troubleshoot prompt with default and custom namespace
  • Troubleshoot prompt with existing and non-existent backup/restore

Other changes

  • Register OADP/Velero CRDs in envtest (pkg/mcp/common_test.go)

Test plan

  • go test -run TestToolsetSuite ./pkg/toolsets/oadp/ -- 8/8 pass
  • go test -run TestOADPSuite ./pkg/mcp/ -- 9/9 pass

Summary by CodeRabbit

  • Tests
    • Expanded OADP/Velero test coverage: test harness now provisions relevant CRDs and a test namespace.
    • Added suites validating OADP toolset registration and prompt surface (presence, description, argument count).
    • Added prompt behavior tests: troubleshooting prompts for default/custom namespaces and integration-style checks that detect existing backups and report missing backups/restores.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 88052be7-5413-4087-b8d1-37d2278daa43

📥 Commits

Reviewing files that changed from the base of the PR and between 6bee000 and 16888b2.

📒 Files selected for processing (3)
  • pkg/mcp/common_test.go
  • pkg/mcp/oadp_test.go
  • pkg/toolsets/oadp/toolset_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/mcp/common_test.go
  • pkg/toolsets/oadp/toolset_test.go
  • pkg/mcp/oadp_test.go

📝 Walkthrough

Walkthrough

Adds OADP/Velero CRDs to envtest and introduces OADP-focused unit and integration tests: a Toolset unit test suite and an MCP OADPSuite that enables CRDs, creates the test namespace, and validates the oadp-troubleshoot prompt, including dynamic-client Backup/Restore scenarios.

Changes

OADP Toolset Test Coverage

Layer / File(s) Summary
Test environment initialization
pkg/mcp/common_test.go
Extends envtest with OADP/Velero CRDs (velero.io backups/restores/backupstoragelocations and oadp.openshift.io DataProtectionApplication).
MCP OADP suite lifecycle & prompt tests
pkg/mcp/oadp_test.go
Adds OADPSuite setup/teardown to enable/disable CRDs and create openshift-adp; per-test setup appends the oadp toolset and initializes the MCP client; includes tests that assert tool registration, render oadp-troubleshoot for default and custom namespaces, and verify Backup/Restore lookup behaviors via the dynamic client.
Toolset unit test suite
pkg/toolsets/oadp/toolset_test.go
Adds unit tests asserting Toolset.GetName() == "oadp", non-empty description, GetTools()/GetResources()/GetResourceTemplates() return nil, and GetPrompts() exposes a single oadp-troubleshoot prompt with three optional args and a non-nil handler.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hoppy tests and CRDs in view,
Hiding bugs with every cue,
Prompts that probe backups and restore,
Namespaces spun, assertions pour,
A little rabbit cheers the suite—hip hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding unit tests for the OADP toolset across three test files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from Cali0707 and Kaustubh-pande June 4, 2026 20:45
@openshift-ci

openshift-ci Bot commented Jun 4, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shubham-pampattiwar
Once this PR has been reviewed and has the lgtm label, please assign cali0707 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
pkg/toolsets/oadp/toolset_test.go (1)

47-54: ⚡ Quick win

Split this subtest into single-behavior assertions.

This block verifies both argument count and per-argument optionality in one test case; split it into focused s.Run() cases for clearer failures.

Suggested refactor
-	s.Run("prompt has three optional arguments", func() {
+	s.Run("prompt has three arguments", func() {
 		t := &Toolset{}
 		prompts := t.GetPrompts()
 		args := prompts[0].Prompt.Arguments
 		s.Len(args, 3)
+	})
+
+	s.Run("prompt arguments are optional", func() {
+		t := &Toolset{}
+		prompts := t.GetPrompts()
+		args := prompts[0].Prompt.Arguments
 		for _, arg := range args {
 			s.False(arg.Required)
 		}
 	})

As per coding guidelines, "One assertion per test case - each s.Run() block should ideally test one specific behavior using testify assertion methods."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/toolsets/oadp/toolset_test.go` around lines 47 - 54, The test combines
two behaviors: verifying the number of arguments and verifying each argument is
optional; split into two focused subtests using s.Run — one like "prompt has
three arguments" that constructs t := &Toolset{}, calls prompts :=
t.GetPrompts(), and asserts s.Len(prompts[0].Prompt.Arguments, 3), and a
separate subtest like "all prompt arguments are optional" that obtains args :=
prompts[0].Prompt.Arguments and iterates asserting s.False(arg.Required) for
each; keep using the same Toolset and GetPrompts symbols and ensure each s.Run
contains only the single focused assertion behavior.
pkg/mcp/oadp_test.go (2)

87-87: ⚡ Quick win

Use s.Require().NoError(err) for must-succeed test steps

These are success-path operations; prefer fail-fast assertions to stop the subtest immediately on error.

Suggested change
-		s.NoError(err)
+		s.Require().NoError(err)

As per coding guidelines, "**/*.go: ... in tests use s.Require().NoError(err) for operations that must succeed and s.Error(err) or s.NoError(err) for testing error conditions".

Also applies to: 117-117, 152-152, 162-162, 174-174

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/mcp/oadp_test.go` at line 87, Replace assertions that must fail-fast by
changing s.NoError(err) to s.Require().NoError(err) for the success-path steps
in this test; specifically update the s.NoError(err) calls (the one at the shown
diff and the other occurrences referenced at lines 117, 152, 162, 174) so the
test stops immediately on unexpected errors. Locate these calls in the oadp_test
(look for s.NoError usages) and switch each to s.Require().NoError(err).

53-53: ⚡ Quick win

Resolve the toolset name at runtime instead of hardcoding it

Line 53 hardcodes "oadp" when extending s.Cfg.Toolsets. Please resolve the name dynamically from the toolset/config source to avoid override/rebrand drift in tests.

As per coding guidelines, "Never hardcode override-prone defaults (ReadOnly, Toolsets, ToolOverrides, ListOutput, toolset names) - read them from s.Cfg or resolve them at runtime".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/mcp/oadp_test.go` at line 53, Replace the hardcoded "oadp" when appending
to s.Cfg.Toolsets with a runtime lookup from the test config—call the config
accessor that returns the toolset name (for example use s.Cfg.ToolsetName(),
s.Cfg.Defaults.Toolset, or a provided ResolveToolset/Lookup method) and append
that result to s.Cfg.Toolsets instead of the literal "oadp"; update the test in
oadp_test.go to derive the toolset name from s.Cfg (use the existing config
getter on s.Cfg rather than hardcoding).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/mcp/oadp_test.go`:
- Line 87: Replace assertions that must fail-fast by changing s.NoError(err) to
s.Require().NoError(err) for the success-path steps in this test; specifically
update the s.NoError(err) calls (the one at the shown diff and the other
occurrences referenced at lines 117, 152, 162, 174) so the test stops
immediately on unexpected errors. Locate these calls in the oadp_test (look for
s.NoError usages) and switch each to s.Require().NoError(err).
- Line 53: Replace the hardcoded "oadp" when appending to s.Cfg.Toolsets with a
runtime lookup from the test config—call the config accessor that returns the
toolset name (for example use s.Cfg.ToolsetName(), s.Cfg.Defaults.Toolset, or a
provided ResolveToolset/Lookup method) and append that result to s.Cfg.Toolsets
instead of the literal "oadp"; update the test in oadp_test.go to derive the
toolset name from s.Cfg (use the existing config getter on s.Cfg rather than
hardcoding).

In `@pkg/toolsets/oadp/toolset_test.go`:
- Around line 47-54: The test combines two behaviors: verifying the number of
arguments and verifying each argument is optional; split into two focused
subtests using s.Run — one like "prompt has three arguments" that constructs t
:= &Toolset{}, calls prompts := t.GetPrompts(), and asserts
s.Len(prompts[0].Prompt.Arguments, 3), and a separate subtest like "all prompt
arguments are optional" that obtains args := prompts[0].Prompt.Arguments and
iterates asserting s.False(arg.Required) for each; keep using the same Toolset
and GetPrompts symbols and ensure each s.Run contains only the single focused
assertion behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 113020db-a9a9-4295-bf1d-7c844ef3ccfd

📥 Commits

Reviewing files that changed from the base of the PR and between 8bff5ed and a4fb74d.

📒 Files selected for processing (3)
  • pkg/mcp/common_test.go
  • pkg/mcp/oadp_test.go
  • pkg/toolsets/oadp/toolset_test.go

@shubham-pampattiwar shubham-pampattiwar force-pushed the feature/oadp-toolset-tests branch from a4fb74d to 6bee000 Compare June 4, 2026 21:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/toolsets/oadp/toolset_test.go`:
- Around line 41-67: The tests access prompts[0] directly in multiple subtests
which can panic if GetPrompts() returns an empty slice; update each affected
subtest (those using prompts[0] in the "prompt is named oadp-troubleshoot",
"prompt has three arguments", and "prompt has a handler" cases) to first assert
the slice is non-empty (e.g., s.NotEmpty(prompts) or s.Len(prompts, X)) before
referencing prompts[0], so failures are reported as assertions instead of
panics; keep the checks around the same variable names (prompts, args) and the
Toolset.GetPrompts() call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 828b0f45-d05a-4096-a041-2dae825528e3

📥 Commits

Reviewing files that changed from the base of the PR and between a4fb74d and 6bee000.

📒 Files selected for processing (3)
  • pkg/mcp/common_test.go
  • pkg/mcp/oadp_test.go
  • pkg/toolsets/oadp/toolset_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/mcp/common_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/mcp/oadp_test.go

Comment thread pkg/toolsets/oadp/toolset_test.go
Add tests for the OADP toolset covering toolset registration (no tools,
prompt exposed) and troubleshoot prompt handler (default/custom namespace,
existing/non-existent backup and restore scenarios).

Register OADP/Velero CRDs in envtest setup.

Follow-up to PR openshift#122 per reviewer request.
@shubham-pampattiwar shubham-pampattiwar force-pushed the feature/oadp-toolset-tests branch from 6bee000 to 16888b2 Compare June 4, 2026 23:15
@openshift-ci

openshift-ci Bot commented Jun 4, 2026

Copy link
Copy Markdown

@shubham-pampattiwar: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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.

1 participant