Test CheckRestart.Validate

This commit is contained in:
Michael Schurter 2017-09-15 15:12:47 -07:00
parent bd3f517f2f
commit c98b79dcb4
2 changed files with 22 additions and 3 deletions

View file

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

View file

@ -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(),