mirror of https://github.com/docker/cli.git
Merge ced6336804
into a5fb752ecf
This commit is contained in:
commit
6aa76111d9
|
@ -758,6 +758,10 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
Name: container.RestartPolicyDisabled,
|
Name: container.RestartPolicyDisabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "no:1",
|
||||||
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: ":1",
|
input: ":1",
|
||||||
expectedErr: "invalid restart policy format: no policy provided before colon",
|
expectedErr: "invalid restart policy format: no policy provided before colon",
|
||||||
|
@ -769,11 +773,8 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "always:1",
|
input: "always:1",
|
||||||
expected: container.RestartPolicy{
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
Name: container.RestartPolicyAlways,
|
|
||||||
MaximumRetryCount: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "always:2:3",
|
input: "always:2:3",
|
||||||
|
@ -796,6 +797,10 @@ func TestParseRestartPolicy(t *testing.T) {
|
||||||
Name: container.RestartPolicyUnlessStopped,
|
Name: container.RestartPolicyUnlessStopped,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "unless-stopped:1",
|
||||||
|
expectedErr: "invalid restart policy: maximum retry count can only be used with 'on-failure'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: "unless-stopped:invalid",
|
input: "unless-stopped:invalid",
|
||||||
expectedErr: "invalid restart policy format: maximum retry count must be an integer",
|
expectedErr: "invalid restart policy format: maximum retry count must be an integer",
|
||||||
|
|
|
@ -79,8 +79,7 @@ func Service(
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
restartPolicy, err := convertRestartPolicy(
|
restartPolicy, err := convertRestartPolicy(service.Restart, service.Deploy.RestartPolicy)
|
||||||
service.Restart, service.Deploy.RestartPolicy)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return swarm.ServiceSpec{}, err
|
return swarm.ServiceSpec{}, err
|
||||||
}
|
}
|
||||||
|
@ -494,7 +493,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
|
||||||
MaxAttempts: &attempts,
|
MaxAttempts: &attempts,
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("unknown restart policy: %s", restart)
|
return nil, errors.Errorf("invalid restart policy: unknown policy '%s'", restart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestConvertRestartPolicyFromNone(t *testing.T) {
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
||||||
_, err := convertRestartPolicy("unknown", nil)
|
_, err := convertRestartPolicy("unknown", nil)
|
||||||
assert.Error(t, err, "unknown restart policy: unknown")
|
assert.Error(t, err, "invalid restart policy: unknown policy 'unknown'; use one of 'no', 'always', 'on-failure', or 'unless-stopped'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
||||||
|
|
|
@ -92,5 +92,8 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Name = container.RestartPolicyMode(k)
|
p.Name = container.RestartPolicyMode(k)
|
||||||
|
if err := container.ValidateRestartPolicy(p); err != nil {
|
||||||
|
return container.RestartPolicy{}, err
|
||||||
|
}
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue