Merge pull request #6375 from abhgupta/abhgupta-dev

Validating against negative weights for priority functions
This commit is contained in:
Daniel Smith 2015-04-02 13:22:55 -07:00
commit 4a3b1a2b9d
2 changed files with 7 additions and 8 deletions

View File

@ -29,8 +29,8 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
validationErrors := make([]error, 0)
for _, priority := range policy.Priorities {
if priority.Weight == 0 {
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a non-zero weight applied to it", priority.Name))
if priority.Weight <= 0 {
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it", priority.Name))
}
}

View File

@ -25,29 +25,28 @@ import (
func TestValidatePriorityWithNoWeight(t *testing.T) {
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority"}}}
if ValidatePolicy(policy) == nil {
t.Errorf("Expected error about priority weight being zero")
t.Errorf("Expected error about priority weight not being positive")
}
}
func TestValidatePriorityWithZeroWeight(t *testing.T) {
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority", Weight: 0}}}
if ValidatePolicy(policy) == nil {
t.Errorf("Expected error about priority weight being zero")
t.Errorf("Expected error about priority weight not being positive")
}
}
func TestValidatePriorityWithNonZeroWeight(t *testing.T) {
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: 2}}}
errs := ValidatePolicy(policy)
if ValidatePolicy(policy) != nil {
if errs != nil {
t.Errorf("Unexpected errors %v", errs)
}
}
func TestValidatePriorityWithNegativeWeight(t *testing.T) {
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: -2}}}
errs := ValidatePolicy(policy)
if ValidatePolicy(policy) != nil {
t.Errorf("Unexpected errors %v", errs)
if ValidatePolicy(policy) == nil {
t.Errorf("Expected error about priority weight not being positive")
}
}