Skip to content

Test: Controller predicates, feature detection, and builder coverage #35

Description

@mannie-exe

Summary

Add and expand unit tests across three domains: controller event predicates (48 specs), runtime feature gate detection (38 specs), and cloudflared builder gap coverage (90 specs). Combined: 176 new specs.

CEL validation coverage (109 specs) split to #40.

Context

These three domains share similar characteristics: moderate complexity, limited scope per domain, and existing test infrastructure in some cases. Bundling them into one issue avoids issue sprawl while keeping work parallelizable within the issue.

Scope

Predicates (48 specs)

Test all 4 custom predicates across 4 event types (Create, Update, Delete, Generic):

Predicate Key Behavior
GenerationOrDeletionPredicate Passes on generation change or non-zero deletion timestamp
CfgateAnnotationOrGenerationPredicate Passes on cfgate.io/* annotation change or generation change
TunnelIDChangedPredicate Passes when .status.tunnelID changes
GatewayCreateAnnotationFilter Passes on create if cfgate annotation present

Also tests unexported helper cfgateAnnotationsChanged.

Requires controller-runtime event types and cfgate API types.

File: internal/controller/predicates_test.go (new)

Feature Detection (38 specs)

Test DetectFeatures() with mock discovery.DiscoveryInterface:

Scenario Specs
All CRDs present 4
Individual CRD missing 8
Discovery error 6
Partial install 8
Upgrade scenarios 6
SupportedRouteKinds 6

File: internal/controller/features/detection_test.go (new)

Builder Gap Coverage (90 specs)

Extend existing builder tests to cover untested functions:

Function Current Coverage Gap
SetCatchAll None 4 specs
ParseConfig None 14 specs
BuildConfigMap None 10 specs
BuildTokenSecret None 10 specs
getMetricsPort None 6 specs
NewTunnelConfig protocol Partial 7 specs
AddRule extended Partial 4 specs
Validate extended Partial 6 specs
Marshal round-trip Partial 4 specs
BuildOriginConfig annotations Partial 25 specs

Files: internal/cloudflared/configmap_test.go, internal/cloudflared/deployment_test.go (extend existing)

References

Acceptance Criteria

  • All 4 custom predicates tested across all event types
  • Feature detection tested with mock discovery
  • Builder gap functions tested
  • All tests pass via go test ./internal/...

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/controllerReconcilers, watches, predicatesarea/testingE2E tests, test infrastructurepriority/p2Nice to havetype/testTest additions and test infrastructure

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions