mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
/*
 | 
						|
Copyright 2019 The Kubernetes Authors.
 | 
						|
 | 
						|
Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
you may not use this file except in compliance with the License.
 | 
						|
You may obtain a copy of the License at
 | 
						|
 | 
						|
    http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 | 
						|
Unless required by applicable law or agreed to in writing, software
 | 
						|
distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
See the License for the specific language governing permissions and
 | 
						|
limitations under the License.
 | 
						|
*/
 | 
						|
 | 
						|
package migration
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
	"reflect"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
 | 
						|
	framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
 | 
						|
)
 | 
						|
 | 
						|
func TestPredicateResultToFrameworkStatus(t *testing.T) {
 | 
						|
	tests := []struct {
 | 
						|
		name       string
 | 
						|
		err        error
 | 
						|
		reasons    []predicates.PredicateFailureReason
 | 
						|
		wantStatus *framework.Status
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			name: "Success",
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:       "Error",
 | 
						|
			err:        errors.New("Failed with error"),
 | 
						|
			wantStatus: framework.NewStatus(framework.Error, "Failed with error"),
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:       "Error with reason",
 | 
						|
			err:        errors.New("Failed with error"),
 | 
						|
			reasons:    []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
 | 
						|
			wantStatus: framework.NewStatus(framework.Error, "Failed with error"),
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:       "Unschedulable",
 | 
						|
			reasons:    []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
 | 
						|
			wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) didn't have free ports for the requested pod ports"),
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:       "Unschedulable and Unresolvable",
 | 
						|
			reasons:    []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts, predicates.ErrNodeSelectorNotMatch},
 | 
						|
			wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "node(s) didn't have free ports for the requested pod ports", "node(s) didn't match node selector"),
 | 
						|
		},
 | 
						|
	}
 | 
						|
	for _, tt := range tests {
 | 
						|
		t.Run(tt.name, func(t *testing.T) {
 | 
						|
			gotStatus := PredicateResultToFrameworkStatus(tt.reasons, tt.err)
 | 
						|
			if !reflect.DeepEqual(tt.wantStatus, gotStatus) {
 | 
						|
				t.Errorf("Got status %v, want %v", gotStatus, tt.wantStatus)
 | 
						|
			}
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 |