@@ -23,4 +23,71 @@ func TestDeepCopyRoundtrip(t *testing.T) {
2323 copied := original .DeepCopy ()
2424 assert .Equal (t , original , copied )
2525 assert .NotSame (t , original , copied )
26+ }
27+
28+ func TestBackendLBPolicyWithCircuitBreaker (t * testing.T ) {
29+ maxInflight := int32 (100 )
30+ policy := & BackendLBPolicy {
31+ ObjectMeta : metav1.ObjectMeta {
32+ Name : "cb-policy" ,
33+ Namespace : "default" ,
34+ },
35+ Spec : BackendLBPolicySpec {
36+ TargetRefs : []LocalPolicyTargetReference {
37+ {Group : "" , Kind : "Service" , Name : "backend-svc" },
38+ },
39+ CircuitBreaker : & CircuitBreakerConfig {
40+ MaxInflightRequests : & maxInflight ,
41+ },
42+ },
43+ }
44+
45+ assert .Equal (t , int32 (100 ), * policy .Spec .CircuitBreaker .MaxInflightRequests )
46+ assert .Len (t , policy .Spec .TargetRefs , 1 )
47+ assert .Equal (t , "backend-svc" , string (policy .Spec .TargetRefs [0 ].Name ))
48+
49+ copied := policy .DeepCopy ()
50+ assert .Equal (t , policy .Spec .CircuitBreaker .MaxInflightRequests , copied .Spec .CircuitBreaker .MaxInflightRequests )
51+ }
52+
53+ func TestBackendLBPolicyWithAllFeatures (t * testing.T ) {
54+ maxInflight := int32 (50 )
55+ lbType := LoadBalancingStrategyTypeConsistentHash
56+ hashKeyType := HashKeyTypeHeader
57+ headerName := "x-tenant-id"
58+
59+ policy := & BackendLBPolicy {
60+ ObjectMeta : metav1.ObjectMeta {
61+ Name : "full-policy" ,
62+ Namespace : "default" ,
63+ },
64+ Spec : BackendLBPolicySpec {
65+ TargetRefs : []LocalPolicyTargetReference {
66+ {Group : "" , Kind : "Service" , Name : "api-svc" },
67+ },
68+ LoadBalancing : & LoadBalancingPolicy {
69+ Type : & lbType ,
70+ ConsistentHash : & ConsistentHashPolicy {
71+ KeyType : & hashKeyType ,
72+ HeaderName : & headerName ,
73+ },
74+ },
75+ CircuitBreaker : & CircuitBreakerConfig {
76+ MaxInflightRequests : & maxInflight ,
77+ },
78+ },
79+ }
80+
81+ assert .NotNil (t , policy .Spec .LoadBalancing )
82+ assert .Equal (t , LoadBalancingStrategyTypeConsistentHash , * policy .Spec .LoadBalancing .Type )
83+ assert .NotNil (t , policy .Spec .CircuitBreaker )
84+ assert .Equal (t , int32 (50 ), * policy .Spec .CircuitBreaker .MaxInflightRequests )
85+
86+ copied := policy .DeepCopy ()
87+ assert .Equal (t , policy , copied )
88+ }
89+
90+ func TestCircuitBreakerConfig_NilMaxInflight (t * testing.T ) {
91+ cfg := & CircuitBreakerConfig {}
92+ assert .Nil (t , cfg .MaxInflightRequests )
2693}
0 commit comments