|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/docker/docker/integration-cli/request"
|
|
"github.com/docker/docker/integration-cli/request"
|
|
@@ -83,3 +84,70 @@ func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) {
|
|
expected = "invalid environment variable: =foo"
|
|
expected = "invalid environment variable: =foo"
|
|
c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {
|
|
|
|
+ // test invalid Interval in Healthcheck: less than 0s
|
|
|
|
+ name := "test1"
|
|
|
|
+ config := map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "Healthcheck": map[string]interface{}{
|
|
|
|
+ "Interval": time.Duration(-10000000),
|
|
|
|
+ "Timeout": time.Duration(1000000000),
|
|
|
|
+ "Retries": int(1000),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ status, body, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
+ expected := "Interval in Healthcheck cannot be less than one second"
|
|
|
|
+ c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
|
|
+
|
|
|
|
+ // test invalid Interval in Healthcheck: larger than 0s but less than 1s
|
|
|
|
+ name = "test2"
|
|
|
|
+ config = map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "Healthcheck": map[string]interface{}{
|
|
|
|
+ "Interval": time.Duration(500000000),
|
|
|
|
+ "Timeout": time.Duration(1000000000),
|
|
|
|
+ "Retries": int(1000),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
+ expected = "Interval in Healthcheck cannot be less than one second"
|
|
|
|
+ c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
|
|
+
|
|
|
|
+ // test invalid Timeout in Healthcheck: less than 1s
|
|
|
|
+ name = "test3"
|
|
|
|
+ config = map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "Healthcheck": map[string]interface{}{
|
|
|
|
+ "Interval": time.Duration(1000000000),
|
|
|
|
+ "Timeout": time.Duration(-100000000),
|
|
|
|
+ "Retries": int(1000),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
+ expected = "Timeout in Healthcheck cannot be less than one second"
|
|
|
|
+ c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
|
|
+
|
|
|
|
+ // test invalid Retries in Healthcheck: less than 0
|
|
|
|
+ name = "test4"
|
|
|
|
+ config = map[string]interface{}{
|
|
|
|
+ "Image": "busybox",
|
|
|
|
+ "Healthcheck": map[string]interface{}{
|
|
|
|
+ "Interval": time.Duration(1000000000),
|
|
|
|
+ "Timeout": time.Duration(1000000000),
|
|
|
|
+ "Retries": int(-10),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+ c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
+ expected = "Retries in Healthcheck cannot be negative"
|
|
|
|
+ c.Assert(getErrorMessage(c, body), checker.Contains, expected)
|
|
|
|
+}
|