mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Update more tests to use new errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
161e0a90a6
commit
ae875d4069
2 changed files with 28 additions and 36 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -14,6 +13,7 @@ import (
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/api/types/versions"
|
"github.com/docker/docker/api/types/versions"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
ctr "github.com/docker/docker/integration/internal/container"
|
ctr "github.com/docker/docker/integration/internal/container"
|
||||||
"github.com/docker/docker/internal/test/request"
|
"github.com/docker/docker/internal/test/request"
|
||||||
"github.com/docker/docker/oci"
|
"github.com/docker/docker/oci"
|
||||||
|
@ -60,6 +60,7 @@ func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
||||||
|
assert.Check(t, errdefs.IsNotFound(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +101,7 @@ func TestCreateWithInvalidEnv(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
||||||
|
assert.Check(t, errdefs.IsInvalidParameter(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,6 +147,7 @@ func TestCreateTmpfsMountsTarget(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
assert.Check(t, is.ErrorContains(err, tc.expectedError))
|
||||||
|
assert.Check(t, errdefs.IsInvalidParameter(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestCreateWithCustomMaskedPaths(t *testing.T) {
|
func TestCreateWithCustomMaskedPaths(t *testing.T) {
|
||||||
|
@ -346,6 +349,7 @@ func TestCreateWithCapabilities(t *testing.T) {
|
||||||
assert.DeepEqual(t, tc.expected, ci.HostConfig.Capabilities)
|
assert.DeepEqual(t, tc.expected, ci.HostConfig.Capabilities)
|
||||||
} else {
|
} else {
|
||||||
assert.ErrorContains(t, err, tc.expectedError)
|
assert.ErrorContains(t, err, tc.expectedError)
|
||||||
|
assert.Check(t, errdefs.IsInvalidParameter(err))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -432,6 +436,8 @@ func TestCreateWithCustomReadonlyPaths(t *testing.T) {
|
||||||
|
|
||||||
func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
|
func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
|
client := testEnv.APIClient()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
doc string
|
doc string
|
||||||
|
@ -479,38 +485,31 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
i := i
|
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.doc, func(t *testing.T) {
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
healthCheck := map[string]interface{}{
|
cfg := container.Config{
|
||||||
"Interval": tc.interval,
|
Image: "busybox",
|
||||||
"Timeout": tc.timeout,
|
Healthcheck: &container.HealthConfig{
|
||||||
"Retries": tc.retries,
|
Interval: tc.interval,
|
||||||
|
Timeout: tc.timeout,
|
||||||
|
Retries: tc.retries,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if tc.startPeriod != 0 {
|
if tc.startPeriod != 0 {
|
||||||
healthCheck["StartPeriod"] = tc.startPeriod
|
cfg.Healthcheck.StartPeriod = tc.startPeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
config := map[string]interface{}{
|
resp, err := client.ContainerCreate(ctx, &cfg, &container.HostConfig{}, nil, "")
|
||||||
"Image": "busybox",
|
assert.Check(t, is.Equal(len(resp.Warnings), 0))
|
||||||
"Healthcheck": healthCheck,
|
|
||||||
}
|
|
||||||
|
|
||||||
res, body, err := request.Post("/containers/create?name="+fmt.Sprintf("test_%d_", i)+t.Name(), request.JSONBody(config))
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
|
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
|
||||||
assert.Check(t, is.Equal(http.StatusInternalServerError, res.StatusCode))
|
assert.Check(t, errdefs.IsSystem(err))
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(http.StatusBadRequest, res.StatusCode))
|
assert.Check(t, errdefs.IsInvalidParameter(err))
|
||||||
}
|
}
|
||||||
|
assert.ErrorContains(t, err, tc.expectedErr)
|
||||||
buf, err := request.ReadBody(body)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
assert.Check(t, is.Contains(string(buf), tc.expectedErr))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,10 +12,10 @@ import (
|
||||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/api/types/versions"
|
"github.com/docker/docker/api/types/versions"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/docker/docker/integration/internal/network"
|
"github.com/docker/docker/integration/internal/network"
|
||||||
"github.com/docker/docker/integration/internal/swarm"
|
"github.com/docker/docker/integration/internal/swarm"
|
||||||
"github.com/docker/docker/internal/test/daemon"
|
"github.com/docker/docker/internal/test/daemon"
|
||||||
"github.com/docker/docker/internal/test/request"
|
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
is "gotest.tools/assert/cmp"
|
is "gotest.tools/assert/cmp"
|
||||||
"gotest.tools/poll"
|
"gotest.tools/poll"
|
||||||
|
@ -129,6 +128,9 @@ func TestCreateServiceConflict(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
|
c := d.NewClientT(t)
|
||||||
|
defer c.Close()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
serviceName := "TestService_" + t.Name()
|
serviceName := "TestService_" + t.Name()
|
||||||
serviceSpec := []swarm.ServiceSpecOpt{
|
serviceSpec := []swarm.ServiceSpecOpt{
|
||||||
|
@ -138,18 +140,9 @@ func TestCreateServiceConflict(t *testing.T) {
|
||||||
swarm.CreateService(t, d, serviceSpec...)
|
swarm.CreateService(t, d, serviceSpec...)
|
||||||
|
|
||||||
spec := swarm.CreateServiceSpec(t, serviceSpec...)
|
spec := swarm.CreateServiceSpec(t, serviceSpec...)
|
||||||
res, body, err := request.Post(
|
_, err := c.ServiceCreate(ctx, spec, types.ServiceCreateOptions{})
|
||||||
"/services/create",
|
assert.Check(t, errdefs.IsConflict(err))
|
||||||
request.Host(d.Sock()),
|
assert.ErrorContains(t, err, "service "+serviceName+" already exists")
|
||||||
request.JSONBody(spec),
|
|
||||||
request.JSON,
|
|
||||||
)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
assert.Equal(t, res.StatusCode, http.StatusConflict)
|
|
||||||
|
|
||||||
buf, err := request.ReadBody(body)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
assert.Check(t, is.Contains(string(buf), "service "+serviceName+" already exists"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateServiceMaxReplicas(t *testing.T) {
|
func TestCreateServiceMaxReplicas(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue