55
66 "github.com/stretchr/testify/assert"
77 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+ "k8s.io/apimachinery/pkg/runtime"
89)
910
1011func TestDeepCopyRoundtrip (t * testing.T ) {
@@ -90,4 +91,48 @@ func TestBackendLBPolicyWithAllFeatures(t *testing.T) {
9091func TestCircuitBreakerConfig_NilMaxInflight (t * testing.T ) {
9192 cfg := & CircuitBreakerConfig {}
9293 assert .Nil (t , cfg .MaxInflightRequests )
94+ }
95+
96+ func TestDeepCopyObject_Nil (t * testing.T ) {
97+ var policy * BackendLBPolicy
98+ assert .Nil (t , policy .DeepCopyObject ())
99+ assert .Nil (t , policy .DeepCopy ())
100+
101+ var list * BackendLBPolicyList
102+ assert .Nil (t , list .DeepCopyObject ())
103+ assert .Nil (t , list .DeepCopy ())
104+ }
105+
106+ func TestBackendLBPolicyListDeepCopy (t * testing.T ) {
107+ list := & BackendLBPolicyList {
108+ Items : []BackendLBPolicy {
109+ {ObjectMeta : metav1.ObjectMeta {Name : "lb1" , Namespace : "ns1" }},
110+ {ObjectMeta : metav1.ObjectMeta {Name : "lb2" , Namespace : "ns2" }},
111+ },
112+ }
113+ copied := list .DeepCopy ()
114+ assert .Equal (t , 2 , len (copied .Items ))
115+ assert .Equal (t , "lb1" , copied .Items [0 ].Name )
116+ assert .NotSame (t , list , copied )
117+ }
118+
119+ func TestAddToScheme (t * testing.T ) {
120+ scheme := runtime .NewScheme ()
121+ err := AddToScheme (scheme )
122+ assert .NoError (t , err )
123+ assert .True (t , scheme .Recognizes (GroupVersion .WithKind ("BackendLBPolicy" )))
124+ assert .True (t , scheme .Recognizes (GroupVersion .WithKind ("BackendLBPolicyList" )))
125+ }
126+
127+ func TestBackendLBPolicyDeepCopy_NilCircuitBreaker (t * testing.T ) {
128+ policy := & BackendLBPolicy {
129+ ObjectMeta : metav1.ObjectMeta {Name : "no-cb" , Namespace : "default" },
130+ Spec : BackendLBPolicySpec {
131+ TargetRefs : []LocalPolicyTargetReference {{Name : "svc" }},
132+ LoadBalancing : & LoadBalancingPolicy {},
133+ },
134+ }
135+ copied := policy .DeepCopy ()
136+ assert .Nil (t , copied .Spec .CircuitBreaker )
137+ assert .NotNil (t , copied .Spec .LoadBalancing )
93138}
0 commit comments