1
0
Fork 0
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:
Sebastiaan van Stijn 2019-01-09 14:47:06 +01:00
parent 161e0a90a6
commit ae875d4069
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 28 additions and 36 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
"testing"
"time"
@ -14,6 +13,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
ctr "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/test/request"
"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, errdefs.IsNotFound(err))
})
}
}
@ -100,6 +101,7 @@ func TestCreateWithInvalidEnv(t *testing.T) {
"",
)
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, errdefs.IsInvalidParameter(err))
}
}
func TestCreateWithCustomMaskedPaths(t *testing.T) {
@ -346,6 +349,7 @@ func TestCreateWithCapabilities(t *testing.T) {
assert.DeepEqual(t, tc.expected, ci.HostConfig.Capabilities)
} else {
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) {
defer setupTest(t)()
client := testEnv.APIClient()
ctx := context.Background()
testCases := []struct {
doc string
@ -479,38 +485,31 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
},
}
for i, tc := range testCases {
i := i
for _, tc := range testCases {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
t.Parallel()
healthCheck := map[string]interface{}{
"Interval": tc.interval,
"Timeout": tc.timeout,
"Retries": tc.retries,
cfg := container.Config{
Image: "busybox",
Healthcheck: &container.HealthConfig{
Interval: tc.interval,
Timeout: tc.timeout,
Retries: tc.retries,
},
}
if tc.startPeriod != 0 {
healthCheck["StartPeriod"] = tc.startPeriod
cfg.Healthcheck.StartPeriod = tc.startPeriod
}
config := map[string]interface{}{
"Image": "busybox",
"Healthcheck": healthCheck,
}
res, body, err := request.Post("/containers/create?name="+fmt.Sprintf("test_%d_", i)+t.Name(), request.JSONBody(config))
assert.NilError(t, err)
resp, err := client.ContainerCreate(ctx, &cfg, &container.HostConfig{}, nil, "")
assert.Check(t, is.Equal(len(resp.Warnings), 0))
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.32") {
assert.Check(t, is.Equal(http.StatusInternalServerError, res.StatusCode))
assert.Check(t, errdefs.IsSystem(err))
} else {
assert.Check(t, is.Equal(http.StatusBadRequest, res.StatusCode))
assert.Check(t, errdefs.IsInvalidParameter(err))
}
buf, err := request.ReadBody(body)
assert.NilError(t, err)
assert.Check(t, is.Contains(string(buf), tc.expectedErr))
assert.ErrorContains(t, err, tc.expectedErr)
})
}
}

View file

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"net/http"
"testing"
"time"
@ -13,10 +12,10 @@ import (
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/integration/internal/network"
"github.com/docker/docker/integration/internal/swarm"
"github.com/docker/docker/internal/test/daemon"
"github.com/docker/docker/internal/test/request"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/poll"
@ -129,6 +128,9 @@ func TestCreateServiceConflict(t *testing.T) {
defer setupTest(t)()
d := swarm.NewSwarm(t, testEnv)
defer d.Stop(t)
c := d.NewClientT(t)
defer c.Close()
ctx := context.Background()
serviceName := "TestService_" + t.Name()
serviceSpec := []swarm.ServiceSpecOpt{
@ -138,18 +140,9 @@ func TestCreateServiceConflict(t *testing.T) {
swarm.CreateService(t, d, serviceSpec...)
spec := swarm.CreateServiceSpec(t, serviceSpec...)
res, body, err := request.Post(
"/services/create",
request.Host(d.Sock()),
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"))
_, err := c.ServiceCreate(ctx, spec, types.ServiceCreateOptions{})
assert.Check(t, errdefs.IsConflict(err))
assert.ErrorContains(t, err, "service "+serviceName+" already exists")
}
func TestCreateServiceMaxReplicas(t *testing.T) {