Skip to content

test(controller): add unit tests for AgentCard syncPeriod validation#257

Merged
pdettori merged 1 commit intokagenti:mainfrom
Schimuneck:RHAIENG-3719-syncperiod-validation
Apr 8, 2026
Merged

test(controller): add unit tests for AgentCard syncPeriod validation#257
pdettori merged 1 commit intokagenti:mainfrom
Schimuneck:RHAIENG-3719-syncperiod-validation

Conversation

@Schimuneck
Copy link
Copy Markdown

Summary

Adds dedicated unit tests for the getSyncPeriod method on the AgentCard controller, covering all edge cases identified in RHAIENG-3719. Also tightens the existing happy-path RequeueAfter assertion from > 0 to the exact expected value.

Test cases added

# Input Expected RequeueAfter Validates
1 "10s" 10 * time.Second Valid short duration parsed correctly
2 "5m" 5 * time.Minute Valid long duration parsed correctly
3 "garbage" DefaultSyncPeriod (30s) Invalid string falls back gracefully
4 "" DefaultSyncPeriod (30s) Empty string falls back gracefully
5 "30s" then patched to "10s" Changes from 30s to 10s Live spec update takes effect on next reconcile

Code paths exercised

  • getSyncPeriod in agentcard_controller.go (empty check, time.ParseDuration, error fallback)
  • Reconcile return path at line 328-331 (ctrl.Result{RequeueAfter: syncPeriod})

Existing test tightened

The happy-path test ("should fetch agent card and override URL with service URL") previously asserted Expect(result.RequeueAfter).To(BeNumerically(">", 0)). Since that test uses SyncPeriod: "30s", the assertion is now Expect(result.RequeueAfter).To(Equal(30 * time.Second)).

Kind cluster validation

All behaviors confirmed manually on Kind (Kubernetes 1.35.0, Podman 5.6.2):

  • syncPeriod: "10s" — operator fetches every ~10s (verified via logs)
  • syncPeriod: "garbage" — operator logs "Invalid sync period, using default" and falls back to ~30s
  • Live patch from "garbage" to "10s" — new period takes effect immediately

Run instructions

make test
# or focused:
go test ./internal/controller/ -v --ginkgo.focus="getSyncPeriod"

Files changed

File Change
kagenti-operator/internal/controller/agentcard_controller_test.go Add "time" import, new Describe("AgentCard Controller - getSyncPeriod") block (5 tests), tighten existing RequeueAfter assertion

Signed-off-by: Matias Schimuneck schimuenck.matias@gmail.com

Adds dedicated tests for getSyncPeriod covering valid durations (10s, 5m),
invalid input ("garbage" falls back to 30s default), empty string (falls
back to 30s default), and live spec updates taking effect on next reconcile.

Tightens the existing happy-path RequeueAfter assertion from "> 0" to
the exact expected value (30s).

Closes RHAIENG-3719

Signed-off-by: Matias Schimuneck <schimuenck.matias@gmail.com>
Made-with: Cursor
@Schimuneck Schimuneck requested a review from a team as a code owner April 1, 2026 11:42
Copy link
Copy Markdown
Contributor

@r3v5 r3v5 left a comment

Choose a reason for hiding this comment

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

Great work, @Schimuneck !

  • Clean reconcileCard helper that encapsulates the two-phase reconcile pattern without masking errors
  • Complete AfterEach cleanup for all current test resources
  • Proper use of Eventually for status updates (no race conditions)
  • Test naming follows existing "AgentCard Controller - " convention
  • Existing assertion tightened from BeNumerically(">", 0) to exact value — good improvement

Copy link
Copy Markdown
Collaborator

@cwiklik cwiklik left a comment

Choose a reason for hiding this comment

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

Review Summary

Clean, well-structured test PR that adds comprehensive coverage for getSyncPeriod — valid durations, invalid input fallback, empty string fallback, and live spec updates. Test patterns follow existing conventions (Ginkgo BDD, proper cleanup, specific assertions). One commit, signed-off, DCO passing.

Areas reviewed: Go (tests), Commit conventions, Security
Commits: 1 commit, signed-off: ✅
CI status: passing (DCO ✅)

Highlights

  • reconcileCard() helper encapsulates the two-phase reconcile pattern cleanly
  • Comprehensive AfterEach cleanup for all test resources
  • Tightening BeNumerically(">", 0)Equal(30 * time.Second) is a good improvement
  • Dynamic update test (30s→10s) covers a real operational scenario

Minor suggestion

The commit contains a Made-with: Cursor trailer. Per kagenti conventions, AI attribution should use Assisted-By: Cursor <noreply@cursor.com> instead of Made-with:. Not blocking — can be fixed with git commit --amend if desired.

Copy link
Copy Markdown
Contributor

@pdettori pdettori left a comment

Choose a reason for hiding this comment

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

Review Summary

Clean, well-structured test PR that adds comprehensive coverage for getSyncPeriod — valid durations, invalid input fallback, empty string fallback, and live spec updates. Test patterns follow existing conventions (Ginkgo BDD, proper cleanup, specific assertions).

Areas reviewed: Go (tests), Commit conventions, Security
Commits: 1 commit, signed-off: ✅
CI status: DCO ✅, static checks ✅, build/unit/e2e pending

Highlights

  • reconcileCard() helper encapsulates the two-phase reconcile pattern cleanly
  • Comprehensive AfterEach cleanup for all test resources (safe get-before-delete pattern)
  • Tightening BeNumerically(">", 0)Equal(30 * time.Second) is a good improvement
  • Dynamic update test (30s→10s) covers a real operational scenario
  • Proper use of DefaultSyncPeriod constant in fallback assertions

Nit

The commit contains a Made-with: Cursor trailer. Per kagenti conventions, AI attribution should use Assisted-By: Cursor <noreply@cursor.com> instead of Made-with:. Not blocking — can be fixed with git commit --amend if desired (already noted by @cwiklik).

@pdettori pdettori merged commit 125b15a into kagenti:main Apr 8, 2026
14 checks passed
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.

4 participants