@@ -249,3 +249,75 @@ func TestSelectBestClusters(t *testing.T) {
249249 })
250250 }
251251}
252+
253+ func TestIgnoreCalculateAvailableResource (t * testing.T ) {
254+ tests := []struct {
255+ name string
256+ placement * policyv1alpha1.Placement
257+ ignore bool
258+ }{
259+ {
260+ name : "when ReplicaScheduling is nil" ,
261+ placement : & policyv1alpha1.Placement {ReplicaScheduling : nil },
262+ ignore : true ,
263+ },
264+ {
265+ name : "when strategy is duplicated" ,
266+ placement : & policyv1alpha1.Placement {
267+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDuplicated },
268+ },
269+ ignore : true ,
270+ },
271+ {
272+ name : "when strategy is divided, and ReplicaDivisionPreference is Aggregated" ,
273+ placement : & policyv1alpha1.Placement {
274+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
275+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
276+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceAggregated ,
277+ },
278+ },
279+ ignore : false ,
280+ },
281+ {
282+ name : "when strategy is divided, and ReplicaDivisionPreference is Weighted, and WeightPreference is nil" ,
283+ placement : & policyv1alpha1.Placement {
284+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
285+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
286+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceWeighted ,
287+ WeightPreference : nil ,
288+ },
289+ },
290+ ignore : true ,
291+ },
292+ {
293+ name : "when strategy is divided, and ReplicaDivisionPreference is Weighted, and WeightPreference is DynamicWeight" ,
294+ placement : & policyv1alpha1.Placement {
295+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
296+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
297+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceWeighted ,
298+ WeightPreference : & policyv1alpha1.ClusterPreferences {DynamicWeight : policyv1alpha1 .DynamicWeightByAvailableReplicas },
299+ },
300+ },
301+ ignore : false ,
302+ },
303+ {
304+ name : "when strategy is divided, and ReplicaDivisionPreference is Weighted, and WeightPreference is StaticWeightList" ,
305+ placement : & policyv1alpha1.Placement {
306+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
307+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
308+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceWeighted ,
309+ WeightPreference : & policyv1alpha1.ClusterPreferences {StaticWeightList : make ([]policyv1alpha1.StaticClusterWeight , 0 )},
310+ },
311+ },
312+ ignore : true ,
313+ },
314+ }
315+ for _ , tt := range tests {
316+ t .Run (tt .name , func (t * testing.T ) {
317+ got := shouldIgnoreCalculateAvailableResource (tt .placement )
318+ if ! reflect .DeepEqual (got , tt .ignore ) {
319+ t .Errorf ("shouldIgnoreCalculateAvailableResource() = %v, want %v" , got , tt .ignore )
320+ }
321+ })
322+ }
323+ }
0 commit comments