...

Source file src/k8s.io/kubernetes/pkg/apis/flowcontrol/internalbootstrap/defaults_test.go

Documentation: k8s.io/kubernetes/pkg/apis/flowcontrol/internalbootstrap

     1  /*
     2  Copyright 2020 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 internalbootstrap
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  
    25  	flowcontrol "k8s.io/api/flowcontrol/v1"
    26  	apiequality "k8s.io/apimachinery/pkg/api/equality"
    27  	"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
    28  )
    29  
    30  func TestBootstrapConfigurationWithDefaulted(t *testing.T) {
    31  	scheme := NewAPFScheme()
    32  
    33  	bootstrapFlowSchemas := make([]*flowcontrol.FlowSchema, 0)
    34  	bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.MandatoryFlowSchemas...)
    35  	bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.SuggestedFlowSchemas...)
    36  	for _, original := range bootstrapFlowSchemas {
    37  		t.Run(fmt.Sprintf("FlowSchema/%s", original.Name), func(t *testing.T) {
    38  			defaulted := original.DeepCopyObject().(*flowcontrol.FlowSchema)
    39  			scheme.Default(defaulted)
    40  			if apiequality.Semantic.DeepEqual(original, defaulted) {
    41  				t.Logf("Defaulting makes no change to FlowSchema: %q", original.Name)
    42  				return
    43  			}
    44  			t.Errorf("Expected defaulting to not change FlowSchema: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
    45  		})
    46  	}
    47  
    48  	bootstrapPriorityLevels := make([]*flowcontrol.PriorityLevelConfiguration, 0)
    49  	bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.MandatoryPriorityLevelConfigurations...)
    50  	bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.SuggestedPriorityLevelConfigurations...)
    51  	for _, original := range bootstrapPriorityLevels {
    52  		t.Run(fmt.Sprintf("PriorityLevelConfiguration/%s", original.Name), func(t *testing.T) {
    53  			defaulted := original.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
    54  			scheme.Default(defaulted)
    55  			if apiequality.Semantic.DeepEqual(original, defaulted) {
    56  				t.Logf("Defaulting makes no change to PriorityLevelConfiguration: %q", original.Name)
    57  				return
    58  			}
    59  			t.Errorf("Expected defaulting to not change PriorityLevelConfiguration: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
    60  		})
    61  	}
    62  }
    63  

View as plain text