Add unit tests for status and condition helper functions

Đang mở
#75 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@aviralgarg05 đang làm issue này rồi.

Từ ngày 9/11/2026.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
68/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
go, kubernetes
Lĩnh vực
backend, testing

Hướng nghiên cứu

Bắt đầu bằng cách đọc các helper và hàm controller được liệt kê trong api/v1alpha1/apikey_types.go và internal/controller/*.go, sau đó kiểm tra các quy ước test ở gần đó. Thêm unit test cho các trường hợp thông thường, nil, biên, nhánh, so sánh và deep-copy được chỉ định mà không dùng envtest. Chạy make test và xác nhận rằng tất cả test đều pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Go
Star
3
Fork
15
Merge trung bình
1 ngày 21 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Kuadrant/developer-portal-controller

Tất cả issue của Kuadrant/developer-portal-controller

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.