Use a default duration if no duration is provided in a profile (#2520)
This commit is contained in:
parent
6c20d38c41
commit
6b5da29e3d
2 changed files with 22 additions and 2 deletions
|
@ -86,8 +86,15 @@ func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
|
||||||
|
|
||||||
for _, decision := range profile.Decisions {
|
for _, decision := range profile.Decisions {
|
||||||
if runtime.RuntimeDurationExpr == nil {
|
if runtime.RuntimeDurationExpr == nil {
|
||||||
if _, err := time.ParseDuration(*decision.Duration); err != nil {
|
var duration string
|
||||||
return []*Runtime{}, errors.Wrapf(err, "error parsing duration '%s' of %s", *decision.Duration, profile.Name)
|
if decision.Duration != nil {
|
||||||
|
duration = *decision.Duration
|
||||||
|
} else {
|
||||||
|
runtime.Logger.Warningf("No duration specified for %s, using default duration %s", profile.Name, defaultDuration)
|
||||||
|
duration = defaultDuration
|
||||||
|
}
|
||||||
|
if _, err := time.ParseDuration(duration); err != nil {
|
||||||
|
return []*Runtime{}, errors.Wrapf(err, "error parsing duration '%s' of %s", duration, profile.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,19 @@ func TestNewProfile(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedNbProfile: 1,
|
expectedNbProfile: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "filter ok and no duration",
|
||||||
|
profileCfg: &csconfig.ProfileCfg{
|
||||||
|
Filters: []string{
|
||||||
|
"1==1",
|
||||||
|
},
|
||||||
|
Debug: &boolTrue,
|
||||||
|
Decisions: []models.Decision{
|
||||||
|
{Type: &typ, Scope: &scope, Simulated: &boolFalse},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedNbProfile: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in a new issue