mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #40404 from tanshanshan/unit-test-scheduler4
Automatic merge from submit-queue (batch tested with PRs 40404, 43134, 43117) Improve code coverage for scheduler/api/validation **What this PR does / why we need it**: Improve code coverage for scheduler/api/validation from #39559 Thanks **Special notes for your reviewer**: **Release note**: ```release-note ```
This commit is contained in:
commit
9e8114655f
@ -286,6 +286,7 @@ plugin/pkg/auth
|
|||||||
plugin/pkg/auth/authenticator/token/bootstrap
|
plugin/pkg/auth/authenticator/token/bootstrap
|
||||||
plugin/pkg/auth/authorizer
|
plugin/pkg/auth/authorizer
|
||||||
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
|
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
|
||||||
|
plugin/pkg/scheduler/api/validation
|
||||||
staging/src/k8s.io/apimachinery/pkg/api/equality
|
staging/src/k8s.io/apimachinery/pkg/api/equality
|
||||||
staging/src/k8s.io/apimachinery/pkg/api/errors
|
staging/src/k8s.io/apimachinery/pkg/api/errors
|
||||||
staging/src/k8s.io/apimachinery/pkg/api/resource
|
staging/src/k8s.io/apimachinery/pkg/api/resource
|
||||||
|
@ -23,10 +23,10 @@ import (
|
|||||||
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate checks for errors in the Config
|
// ValidatePolicy checks for errors in the Config
|
||||||
// It does not return early so that it can find as many errors as possible
|
// It does not return early so that it can find as many errors as possible
|
||||||
func ValidatePolicy(policy schedulerapi.Policy) error {
|
func ValidatePolicy(policy schedulerapi.Policy) error {
|
||||||
validationErrors := make([]error, 0)
|
var validationErrors []error
|
||||||
|
|
||||||
for _, priority := range policy.Priorities {
|
for _, priority := range policy.Priorities {
|
||||||
if priority.Weight <= 0 {
|
if priority.Weight <= 0 {
|
||||||
|
@ -50,3 +50,18 @@ func TestValidatePriorityWithNegativeWeight(t *testing.T) {
|
|||||||
t.Errorf("Expected error about priority weight not being positive")
|
t.Errorf("Expected error about priority weight not being positive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateExtenderWithNonNegativeWeight(t *testing.T) {
|
||||||
|
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: 2}}}
|
||||||
|
errs := ValidatePolicy(extenderPolicy)
|
||||||
|
if errs != nil {
|
||||||
|
t.Errorf("Unexpected errors %v", errs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateExtenderWithNegativeWeight(t *testing.T) {
|
||||||
|
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: -2}}}
|
||||||
|
if ValidatePolicy(extenderPolicy) == nil {
|
||||||
|
t.Errorf("Expected error about priority weight for extender not being positive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user