test(controller): add unit tests for AgentCard syncPeriod validation#257
Conversation
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
r3v5
left a comment
There was a problem hiding this comment.
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
cwiklik
left a comment
There was a problem hiding this comment.
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
AfterEachcleanup 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.
pdettori
left a comment
There was a problem hiding this comment.
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
AfterEachcleanup 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
DefaultSyncPeriodconstant 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).
Summary
Adds dedicated unit tests for the
getSyncPeriodmethod on the AgentCard controller, covering all edge cases identified in RHAIENG-3719. Also tightens the existing happy-pathRequeueAfterassertion from> 0to the exact expected value.Test cases added
RequeueAfter"10s"10 * time.Second"5m"5 * time.Minute"garbage"DefaultSyncPeriod(30s)""DefaultSyncPeriod(30s)"30s"then patched to"10s"Code paths exercised
getSyncPeriodinagentcard_controller.go(empty check,time.ParseDuration, error fallback)Reconcilereturn 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 usesSyncPeriod: "30s", the assertion is nowExpect(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"garbage"to"10s"— new period takes effect immediatelyRun instructions
Files changed
kagenti-operator/internal/controller/agentcard_controller_test.go"time"import, newDescribe("AgentCard Controller - getSyncPeriod")block (5 tests), tighten existingRequeueAfterassertionSigned-off-by: Matias Schimuneck schimuenck.matias@gmail.com