github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/qos/net_enhancement_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 qos 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 v1 "k8s.io/api/core/v1" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 26 "github.com/kubewharf/katalyst-api/pkg/consts" 27 ) 28 29 func TestGetPodNetClassID(t *testing.T) { 30 t.Parallel() 31 32 for _, tc := range []struct { 33 name string 34 pod *v1.Pod 35 expectExist bool 36 expectClassID uint32 37 }{ 38 { 39 name: "pod-level net class id exists", 40 pod: &v1.Pod{ 41 ObjectMeta: metav1.ObjectMeta{ 42 Name: "test-pod-1", 43 Annotations: map[string]string{ 44 consts.PodAnnotationNetClassKey: "123456", 45 }, 46 }, 47 }, 48 expectExist: true, 49 expectClassID: 123456, 50 }, 51 { 52 name: "pod-level net class id doesn't exist", 53 pod: &v1.Pod{ 54 ObjectMeta: metav1.ObjectMeta{ 55 Name: "test-pod-2", 56 }, 57 }, 58 expectExist: false, 59 expectClassID: 0, 60 }, 61 } { 62 tc := tc 63 t.Run(tc.name, func(t *testing.T) { 64 t.Parallel() 65 66 t.Logf("case: %v", tc.name) 67 gotExist, gotClassID, err := GetPodNetClassID(tc.pod.Annotations, consts.PodAnnotationNetClassKey) 68 assert.NoError(t, err) 69 assert.Equal(t, tc.expectExist, gotExist) 70 assert.Equal(t, tc.expectClassID, gotClassID) 71 }) 72 } 73 }