Skip to content

Commit 9e81146

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#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 kubernetes#39559 Thanks **Special notes for your reviewer**: **Release note**: ```release-note ```
2 parents 0afdcfc + 6fd76dc commit 9e81146

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

hack/.linted_packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ plugin/pkg/auth
286286
plugin/pkg/auth/authenticator/token/bootstrap
287287
plugin/pkg/auth/authorizer
288288
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
289+
plugin/pkg/scheduler/api/validation
289290
staging/src/k8s.io/apimachinery/pkg/api/equality
290291
staging/src/k8s.io/apimachinery/pkg/api/errors
291292
staging/src/k8s.io/apimachinery/pkg/api/resource

plugin/pkg/scheduler/api/validation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
2424
)
2525

26-
// Validate checks for errors in the Config
26+
// ValidatePolicy checks for errors in the Config
2727
// It does not return early so that it can find as many errors as possible
2828
func ValidatePolicy(policy schedulerapi.Policy) error {
29-
validationErrors := make([]error, 0)
29+
var validationErrors []error
3030

3131
for _, priority := range policy.Priorities {
3232
if priority.Weight <= 0 {

plugin/pkg/scheduler/api/validation/validation_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ func TestValidatePriorityWithNegativeWeight(t *testing.T) {
5050
t.Errorf("Expected error about priority weight not being positive")
5151
}
5252
}
53+
54+
func TestValidateExtenderWithNonNegativeWeight(t *testing.T) {
55+
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: 2}}}
56+
errs := ValidatePolicy(extenderPolicy)
57+
if errs != nil {
58+
t.Errorf("Unexpected errors %v", errs)
59+
}
60+
}
61+
62+
func TestValidateExtenderWithNegativeWeight(t *testing.T) {
63+
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: -2}}}
64+
if ValidatePolicy(extenderPolicy) == nil {
65+
t.Errorf("Expected error about priority weight for extender not being positive")
66+
}
67+
}

0 commit comments

Comments
 (0)