Skip to content

Commit

Permalink
fix and skip some tests based on API version
Browse files Browse the repository at this point in the history
Signed-off-by: Anda Xu <anda.xu@docker.com>

Co-authored-by: Anda Xu <anda.xu@docker.com>
Co-authored-by: Tibor Vass <tibor@docker.com>
  • Loading branch information
AntaresS and Tibor Vass committed May 15, 2018
1 parent 85a8252 commit e440831
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 70 deletions.
3 changes: 2 additions & 1 deletion integration-cli/docker_api_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) {
}

func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) {
testRequires(c, DaemonIsLinux)
// new feature added in 1.31 - https://github.com/moby/moby/pull/34263
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.31"))
dockerfile := `FROM busybox
RUN echo 'test1:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'test1:x:1001:' >> /etc/group
Expand Down
73 changes: 60 additions & 13 deletions integration-cli/docker_api_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
containertypes "github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
Expand Down Expand Up @@ -724,13 +725,23 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
// Try with no content-type
res, body, err := create("")
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
// todo: we need to figure out a better way to compare between dockerd versions
// comparing between daemon API version is not precise.
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
body.Close()

// Try with wrong content-type
res, body, err = create("application/xml")
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
body.Close()

// now application/json
Expand All @@ -756,7 +767,11 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {

res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}

b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -776,7 +791,11 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)

res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}

b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -796,7 +815,11 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {

res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}

b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -816,7 +839,11 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C

res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}

b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand Down Expand Up @@ -901,7 +928,11 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
b, err2 := request.ReadBody(body)
c.Assert(err2, checker.IsNil)

c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB")
}

Expand Down Expand Up @@ -1089,7 +1120,11 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *check.C) {

res, body, err := request.Post("/v1.23/containers/"+name+"/copy", request.JSONBody(postData))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b), checker.Matches, "Path cannot be empty\n")
Expand All @@ -1106,8 +1141,11 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C)

res, body, err := request.Post("/v1.23/containers/"+name+"/copy", request.JSONBody(postData))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusNotFound)

if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, checker.Equals, http.StatusNotFound)
}
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
Expand Down Expand Up @@ -1563,7 +1601,11 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
c.Assert(err, check.IsNil)

c.Assert(containerJSON.HostConfig.MemorySwappiness, check.IsNil)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.31") {
c.Assert(*containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1))
} else {
c.Assert(containerJSON.HostConfig.MemorySwappiness, check.IsNil)
}
}

// check validation is done daemon side and not only in cli
Expand Down Expand Up @@ -1910,8 +1952,13 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
}

var selinuxSharedLabel string
if runtime.GOOS == "linux" {
selinuxSharedLabel = "z"
// this test label was added after a bug fix in 1.32, thus add requirements min API >= 1.32
// for the sake of making test pass in earlier versions
// bug fixed in https://github.com/moby/moby/pull/34684
if !versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
if runtime.GOOS == "linux" {
selinuxSharedLabel = "z"
}
}

cases := []testCase{
Expand Down
31 changes: 26 additions & 5 deletions integration-cli/docker_api_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/internal/test/request"
"github.com/go-check/check"
Expand All @@ -25,7 +26,11 @@ func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {

res, body, err := request.Post("/containers/create?name="+name, request.JSONBody(config))
c.Assert(err, check.IsNil)
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
}

buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -49,7 +54,11 @@ func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {
buf, err = request.ReadBody(body)
c.Assert(err, checker.IsNil)

c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
}
c.Assert(getErrorMessage(c, buf), checker.Contains, expected)

// test invalid Timeout in Healthcheck: less than 1ms
Expand All @@ -64,7 +73,11 @@ func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {
}
res, body, err = request.Post("/containers/create?name="+name, request.JSONBody(config))
c.Assert(err, check.IsNil)
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
}

buf, err = request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -84,7 +97,11 @@ func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {
}
res, body, err = request.Post("/containers/create?name="+name, request.JSONBody(config))
c.Assert(err, check.IsNil)
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
}

buf, err = request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand All @@ -105,7 +122,11 @@ func (s *DockerSuite) TestAPICreateWithInvalidHealthcheckParams(c *check.C) {
}
res, body, err = request.Post("/containers/create?name="+name, request.JSONBody(config))
c.Assert(err, check.IsNil)
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
}

buf, err = request.ReadBody(body)
c.Assert(err, checker.IsNil)
Expand Down
7 changes: 6 additions & 1 deletion integration-cli/docker_api_exec_resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"

"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/internal/test/request"
"github.com/go-check/check"
Expand All @@ -22,7 +23,11 @@ func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) {
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
res, _, err := request.Post(endpoint)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
}
}

// Part of #14845
Expand Down
21 changes: 16 additions & 5 deletions integration-cli/docker_api_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/internal/test/request"
Expand All @@ -27,8 +28,11 @@ func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) {

res, body, err := request.Post(fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": nil}))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)

if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
}
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)

Expand All @@ -47,8 +51,11 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) {

res, body, err := request.Post(fmt.Sprintf("/containers/%s/exec", name), request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType("test/plain"))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)

if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
} else {
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
}
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)

Expand Down Expand Up @@ -191,7 +198,11 @@ func (s *DockerSuite) TestExecAPIStartInvalidCommand(c *check.C) {
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")

id := createExecCmd(c, name, "invalid")
startExec(c, id, http.StatusBadRequest)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
startExec(c, id, http.StatusNotFound)
} else {
startExec(c, id, http.StatusBadRequest)
}
waitForExec(c, id)

var inspectJSON struct{ ExecIDs []string }
Expand Down
4 changes: 2 additions & 2 deletions integration-cli/docker_api_ipcmode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func testIpcNonePrivateShareable(c *check.C, mode string, mustBeMounted bool, mu
* /dev/shm mount inside the container.
*/
func (s *DockerSuite) TestAPIIpcModeNone(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.32"))
testIpcNonePrivateShareable(c, "none", false, false)
}

Expand Down Expand Up @@ -173,7 +173,7 @@ func (s *DockerSuite) TestAPIIpcModeShareableAndContainer(c *check.C) {
* --ipc container:ID can NOT use IPC of another private container.
*/
func (s *DockerSuite) TestAPIIpcModePrivateAndContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.32"))
testIpcContainer(s, c, "private", false)
}

Expand Down
1 change: 1 addition & 0 deletions integration-cli/docker_api_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (s *DockerSuite) TestLogsAPIUntilFutureFollow(c *check.C) {
}

func (s *DockerSuite) TestLogsAPIUntil(c *check.C) {
testRequires(c, MinimumAPIVersion("1.34"))
name := "logsuntil"
dockerCmd(c, "run", "--name", name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do echo log$i; sleep 1; done")

Expand Down
Loading

0 comments on commit e440831

Please sign in to comment.