better testing of scaling parsing, fixed some broken tests by api
changes
This commit is contained in:
parent
bdbb066ec8
commit
a77e012220
|
@ -1320,7 +1320,7 @@ func TestParse(t *testing.T) {
|
|||
Name: helper.StringToPtr("group"),
|
||||
Scaling: &api.ScalingPolicy{
|
||||
Min: helper.Int64ToPtr(5),
|
||||
Max: 100,
|
||||
Max: helper.Int64ToPtr(100),
|
||||
Policy: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"b": true,
|
||||
|
@ -1345,7 +1345,7 @@ func TestParse(t *testing.T) {
|
|||
Name: helper.StringToPtr("group"),
|
||||
Scaling: &api.ScalingPolicy{
|
||||
Min: nil,
|
||||
Max: 0,
|
||||
Max: helper.Int64ToPtr(10),
|
||||
Policy: nil,
|
||||
Enabled: nil,
|
||||
},
|
||||
|
@ -1355,6 +1355,12 @@ func TestParse(t *testing.T) {
|
|||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"tg-scaling-policy-missing-max.hcl",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
|
||||
{
|
||||
"tg-scaling-policy-multi-policy.hcl",
|
||||
nil,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
job "elastic" {
|
||||
group "group" {
|
||||
scaling {}
|
||||
scaling {
|
||||
max = 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
job "elastic" {
|
||||
group "group" {
|
||||
scaling {
|
||||
// required: max = ...
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5952,12 +5952,15 @@ func (tg *TaskGroup) validateScalingPolicy(j *Job) error {
|
|||
if tg.Scaling.Max < 0 {
|
||||
mErr.Errors = append(mErr.Errors,
|
||||
fmt.Errorf("Scaling policy invalid: maximum count must be specified and non-negative"))
|
||||
} else if tg.Scaling.Max < tg.Scaling.Min {
|
||||
mErr.Errors = append(mErr.Errors,
|
||||
fmt.Errorf("Scaling policy invalid: maximum count must not be less than minimum count"))
|
||||
} else if tg.Scaling.Max < int64(tg.Count) {
|
||||
mErr.Errors = append(mErr.Errors,
|
||||
fmt.Errorf("Scaling policy invalid: task group count must not be greater than maximum count in scaling policy"))
|
||||
} else {
|
||||
if tg.Scaling.Max < tg.Scaling.Min {
|
||||
mErr.Errors = append(mErr.Errors,
|
||||
fmt.Errorf("Scaling policy invalid: maximum count must not be less than minimum count"))
|
||||
}
|
||||
if tg.Scaling.Max < int64(tg.Count) {
|
||||
mErr.Errors = append(mErr.Errors,
|
||||
fmt.Errorf("Scaling policy invalid: task group count must not be greater than maximum count in scaling policy"))
|
||||
}
|
||||
}
|
||||
|
||||
if int64(tg.Count) < tg.Scaling.Min && !(j.IsMultiregion() && tg.Count == 0 && j.Region == "global") {
|
||||
|
|
Loading…
Reference in New Issue