k8s.io/kubernetes@v1.29.3/pkg/scheduler/framework/autoscaler_contract/framework_contract_test.go (about) 1 /* 2 Copyright 2022 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 // This file helps to detect whether we changed the interface of Framework. 18 // This is important for projects under `github.com/kubernetes*` orgs 19 // who import the Framework to not breaking their codes, e.g. cluster-autoscaler. 20 21 package contract 22 23 import ( 24 "context" 25 "testing" 26 27 "github.com/stretchr/testify/assert" 28 v1 "k8s.io/api/core/v1" 29 "k8s.io/klog/v2/ktesting" 30 "k8s.io/kubernetes/pkg/scheduler/framework" 31 "k8s.io/kubernetes/pkg/scheduler/framework/runtime" 32 ) 33 34 type frameworkContract interface { 35 RunPreFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) 36 RunFilterPlugins(context.Context, *framework.CycleState, *v1.Pod, *framework.NodeInfo) *framework.Status 37 } 38 39 func TestFrameworkContract(t *testing.T) { 40 var f framework.Framework 41 var c frameworkContract = f 42 assert.Nil(t, c) 43 } 44 45 func TestNewFramework(t *testing.T) { 46 _, ctx := ktesting.NewTestContext(t) 47 var f interface{} 48 if f, _ = runtime.NewFramework(ctx, nil, nil); f != nil { 49 _, ok := f.(framework.Framework) 50 assert.True(t, ok) 51 } 52 } 53 54 func TestNewCycleState(t *testing.T) { 55 var state interface{} = framework.NewCycleState() 56 _, ok := state.(*framework.CycleState) 57 assert.True(t, ok) 58 }