...
1
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