Use a default duration if no duration is provided in a profile (#2520)

This commit is contained in:
blotus 2023-10-06 14:43:17 +02:00 committed by GitHub
parent 6c20d38c41
commit 6b5da29e3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -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)
} }
} }
} }

View file

@ -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 {