github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/orm/topology/policy_restricted_test.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package topology 18 19 import ( 20 "testing" 21 ) 22 23 func TestPolicyRestrictedName(t *testing.T) { 24 t.Parallel() 25 26 tcases := []struct { 27 name string 28 expected string 29 }{ 30 { 31 name: "New Restricted Policy", 32 expected: "restricted", 33 }, 34 } 35 for _, tc := range tcases { 36 policy := NewRestrictedPolicy([]int{0, 1}) 37 if policy.Name() != tc.expected { 38 t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name()) 39 } 40 } 41 } 42 43 func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) { 44 t.Parallel() 45 46 tcases := []struct { 47 name string 48 hint TopologyHint 49 expected bool 50 }{ 51 { 52 name: "Preferred is set to false in topology hints", 53 hint: TopologyHint{nil, false}, 54 expected: false, 55 }, 56 { 57 name: "Preferred is set to true in topology hints", 58 hint: TopologyHint{nil, true}, 59 expected: true, 60 }, 61 } 62 63 for _, tc := range tcases { 64 numaNodes := []int{0, 1} 65 policy := NewRestrictedPolicy(numaNodes) 66 result := policy.(*restrictedPolicy).canAdmitPodResult(&tc.hint) 67 68 if result != tc.expected { 69 t.Errorf("Expected result to be %t, got %t", tc.expected, result) 70 } 71 } 72 } 73 74 func TestPolicyRestrictedMerge(t *testing.T) { 75 t.Parallel() 76 77 numaNodes := []int{0, 1, 2, 3} 78 policy := NewRestrictedPolicy(numaNodes) 79 80 tcases := commonPolicyMergeTestCases(numaNodes) 81 tcases = append(tcases, policy.(*restrictedPolicy).mergeTestCases(numaNodes)...) 82 83 testPolicyMerge(policy, tcases, t) 84 }