Merge pull request #14377 from coolljt0725/validate_restart_policy

Validate restart policy. Fixes #14351
This commit is contained in:
Doug Davis 2015-07-03 07:01:44 -05:00
Родитель 7b0666f568 f3faf59925
Коммит 0dedadd4d6
2 изменённых файлов: 7 добавлений и 8 удалений

Просмотреть файл

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

Просмотреть файл

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