diff --git a/runconfig/parse.go b/runconfig/parse.go index 552a648330..d512bd3078 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -428,12 +428,15 @@ func ParseRestartPolicy(policy string) (RestartPolicy, error) { p.Name = name switch name { case "always": - if len(parts) == 2 { + if len(parts) > 1 { return p, fmt.Errorf("maximum restart count not valid with restart policy of \"always\"") } case "no": // do nothing case "on-failure": + if len(parts) > 2 { + return p, fmt.Errorf("restart count format is not valid, usage: 'on-failure:N' or 'on-failure'") + } if len(parts) == 2 { count, err := strconv.Atoi(parts[1]) if err != nil { diff --git a/runconfig/parse_test.go b/runconfig/parse_test.go index d858c2570a..d1f3c69eb0 100644 --- a/runconfig/parse_test.go +++ b/runconfig/parse_test.go @@ -456,12 +456,13 @@ func TestParseRestartPolicy(t *testing.T) { invalids := map[string]string{ "something": "invalid restart policy something", "always:2": "maximum restart count not valid with restart policy of \"always\"", + "always:2:3": "maximum restart count not valid with restart policy of \"always\"", "on-failure:invalid": `strconv.ParseInt: parsing "invalid": invalid syntax`, + "on-failure:2:5": "restart count format is not valid, usage: 'on-failure:N' or 'on-failure'", } valids := map[string]RestartPolicy{ "": {}, - // FIXME This feels not right - "always:1:2": { + "always": { Name: "always", MaximumRetryCount: 0, }, @@ -469,11 +470,6 @@ func TestParseRestartPolicy(t *testing.T) { Name: "on-failure", MaximumRetryCount: 1, }, - // FIXME This doesn't feel right - "on-failure:1:2": { - Name: "on-failure", - MaximumRetryCount: 0, - }, } for restart, expectedError := range invalids { if _, _, _, err := parseRun([]string{fmt.Sprintf("--restart=%s", restart), "img", "cmd"}); err == nil || err.Error() != expectedError {