k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/scheduler/framework/plugins/nodename/node_name_test.go (about) 1 /* 2 Copyright 2019 The Kubernetes 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 nodename 18 19 import ( 20 "reflect" 21 "testing" 22 23 v1 "k8s.io/api/core/v1" 24 "k8s.io/kubernetes/pkg/scheduler/framework" 25 st "k8s.io/kubernetes/pkg/scheduler/testing" 26 "k8s.io/kubernetes/test/utils/ktesting" 27 ) 28 29 func TestNodeName(t *testing.T) { 30 tests := []struct { 31 pod *v1.Pod 32 node *v1.Node 33 name string 34 wantStatus *framework.Status 35 }{ 36 { 37 pod: &v1.Pod{}, 38 node: &v1.Node{}, 39 name: "no host specified", 40 }, 41 { 42 pod: st.MakePod().Node("foo").Obj(), 43 node: st.MakeNode().Name("foo").Obj(), 44 name: "host matches", 45 }, 46 { 47 pod: st.MakePod().Node("bar").Obj(), 48 node: st.MakeNode().Name("foo").Obj(), 49 name: "host doesn't match", 50 wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReason), 51 }, 52 } 53 54 for _, test := range tests { 55 t.Run(test.name, func(t *testing.T) { 56 nodeInfo := framework.NewNodeInfo() 57 nodeInfo.SetNode(test.node) 58 _, ctx := ktesting.NewTestContext(t) 59 p, err := New(ctx, nil, nil) 60 if err != nil { 61 t.Fatalf("creating plugin: %v", err) 62 } 63 gotStatus := p.(framework.FilterPlugin).Filter(ctx, nil, test.pod, nodeInfo) 64 if !reflect.DeepEqual(gotStatus, test.wantStatus) { 65 t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus) 66 } 67 }) 68 } 69 }