Test CheckRestart.Validate
This commit is contained in:
parent
bd3f517f2f
commit
c98b79dcb4
|
@ -2780,15 +2780,16 @@ func (c *CheckRestart) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var mErr multierror.Error
|
||||
if c.Limit < 0 {
|
||||
return fmt.Errorf("limit must be greater than or equal to 0 but found %d", c.Limit)
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("limit must be greater than or equal to 0 but found %d", c.Limit))
|
||||
}
|
||||
|
||||
if c.Grace < 0 {
|
||||
return fmt.Errorf("grace period must be greater than or equal to 0 but found %d", c.Grace)
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("grace period must be greater than or equal to 0 but found %d", c.Grace))
|
||||
}
|
||||
|
||||
return nil
|
||||
return mErr.ErrorOrNil()
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -1154,6 +1154,24 @@ func TestTask_Validate_Service_Check(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTask_Validate_Service_Check_CheckRestart(t *testing.T) {
|
||||
invalidCheckRestart := &CheckRestart{
|
||||
Limit: -1,
|
||||
Grace: -1,
|
||||
}
|
||||
|
||||
err := invalidCheckRestart.Validate()
|
||||
assert.NotNil(t, err, "invalidateCheckRestart.Validate()")
|
||||
assert.Len(t, err.(*multierror.Error).Errors, 2)
|
||||
|
||||
validCheckRestart := &CheckRestart{}
|
||||
assert.Nil(t, validCheckRestart.Validate())
|
||||
|
||||
validCheckRestart.Limit = 1
|
||||
validCheckRestart.Grace = 1
|
||||
assert.Nil(t, validCheckRestart.Validate())
|
||||
}
|
||||
|
||||
func TestTask_Validate_LogConfig(t *testing.T) {
|
||||
task := &Task{
|
||||
LogConfig: DefaultLogConfig(),
|
||||
|
|
Loading…
Reference in a new issue