Add unit tests for status and condition helper functions

Aperta
#75 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@aviralgarg05 ci sta già lavorando.

Dal 9/11/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
68/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
go, kubernetes
Ambito
backend, testing

Direzione di ricerca

Inizia leggendo gli helper e le funzioni del controller indicati in api/v1alpha1/apikey_types.go e internal/controller/*.go, quindi esamina le convenzioni dei test vicini. Aggiungi unit test per i casi specificati normali, nil, di limite, di ramo, di confronto e di deep-copy, senza envtest. Esegui make test e conferma che tutti i test passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement good first issue triage/accepted

Summary

Write unit tests for the pure functions that check, compare, and build Kubernetes status conditions. These are critical to the controller's decision-making and are all testable without envtest.

Testing Guidance

For each function, think about:

  • What does it return for normal, expected input?
  • What happens at the boundaries — nil conditions, empty slices, missing fields?
  • If there's branching logic, have you covered each branch?

Scope

api/v1alpha1/apikey_types.go
  • IsApproved() — checks whether an APIKey has an "Approved" condition set to True. Consider: condition present and True, condition present and False, no conditions at all, nil status.
internal/controller/apiproduct_helper.go
  • IsAuthPolicyAcceptedAndEnforced() — returns true only when both Accepted and Enforced conditions are True. Think about each combination: both true, one true, neither, nil policy.
  • IsAuthPolicyAccepted(), IsAuthPolicyEnforced() — individual condition checks.
  • IsAuthPolicyConditionTrue() — generic condition checker. Handles nil policy — test that path.
internal/controller/apiproduct_controller.go
  • authPolicyDiscoveredCondition() — builds a condition reflecting whether an AuthPolicy was found and is accepted+enforced. Test with nil policy, found but not enforced, and fully healthy.
  • openAPISpecReadyCondition() — builds a condition for OpenAPI spec readiness. Has three paths: no URL configured (returns nil), fetch error, and success.
  • oidcDiscoveredCondition() — builds a condition for OIDC discovery. Has three paths: no auth scheme, fetch error, and success.
internal/controller/apikey_status_controller.go
  • getInvalidReason() — returns a reason string from a condition, or a default if nil. Simple null-safe getter.
internal/controller/apikeyrequest_status_controller.go
  • conditionsEqual() — compares two condition slices ignoring LastTransitionTime. Think about: same conditions, different order, different status, empty slices, nil.
  • copyConditions() — deep copies a condition slice. Verify the copy is independent of the original (mutating the copy shouldn't affect the source).

Review & Verification

PRs should include:

  • How to review the changes (areas of interest, suggested review order)
  • Steps to confirm locally: make test runs and passes
Lingua principale
Go
Stelle
3
Fork
15
Merge medio
1g 21h
PR unite (30g)
4

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Kuadrant/developer-portal-controller

Tutte le issue di Kuadrant/developer-portal-controller

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.