Convert assert.Check(t, is.Error()) to assert.Error

git grep -l -P '^\s+assert\.Check\(t, is\.Error\(' | \
    xargs perl -pi -e 's/^(\s+assert\.)Check\(t, is\.Error\((.*)\)$/\1Error(t, \2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-03-06 15:54:24 -05:00
parent f21276575f
commit e15b208e96
47 changed files with 83 additions and 88 deletions

View File

@ -38,7 +38,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, err := LoadFile(reader)
assert.Check(t, is.Error(err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value")) assert.Error(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value")
} }
func TestLoadFileTypeError(t *testing.T) { func TestLoadFileTypeError(t *testing.T) {
@ -53,7 +53,7 @@ func TestLoadFileTypeError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, err := LoadFile(reader)
assert.Check(t, is.Error(err, "Unexpected type at byte 94. Expected []string but received string.")) assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string.")
} }
func TestPrint(t *testing.T) { func TestPrint(t *testing.T) {

View File

@ -74,6 +74,6 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {
cmd := newConfigRemoveCommand(cli) cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), "error removing config: foo")) assert.Error(t, cmd.Execute(), "error removing config: foo")
assert.Check(t, is.DeepEqual(names, removedConfigs)) assert.Check(t, is.DeepEqual(names, removedConfigs))
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -124,7 +123,7 @@ func TestGetExitStatus(t *testing.T) {
if testcase.expectedError == nil { if testcase.expectedError == nil {
assert.NilError(t, err) assert.NilError(t, err)
} else { } else {
assert.Check(t, is.Error(err, testcase.expectedError.Error())) assert.Error(t, err, testcase.expectedError.Error())
} }
} }
} }

View File

@ -43,7 +43,7 @@ func TestRunCopyWithInvalidArguments(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) { t.Run(testcase.doc, func(t *testing.T) {
err := runCopy(test.NewFakeCli(nil), testcase.options) err := runCopy(test.NewFakeCli(nil), testcase.options)
assert.Check(t, is.Error(err, testcase.expectedErr)) assert.Error(t, err, testcase.expectedErr)
}) })
} }
} }

View File

@ -244,7 +244,7 @@ size: 0B
testcase.context.Output = out testcase.context.Output = out
err := ContainerWrite(testcase.context, containers) err := ContainerWrite(testcase.context, containers)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -52,7 +52,7 @@ D: /usr/app/old_app.js
testcase.context.Output = out testcase.context.Output = out
err := DiffWrite(testcase.context, diffs) err := DiffWrite(testcase.context, diffs)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -294,7 +294,7 @@ image_id: imageID3
testcase.context.Output = out testcase.context.Output = out
err := ImageWrite(testcase.context, images) err := ImageWrite(testcase.context, images)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -162,7 +162,7 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
testcase.context.Output = out testcase.context.Output = out
err := NetworkWrite(testcase.context, networks) err := NetworkWrite(testcase.context, networks)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -203,7 +203,7 @@ foobar_boo Unknown
testcase.context.Output = out testcase.context.Output = out
err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}}) err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -132,7 +132,7 @@ foobar_bar
testcase.context.Output = out testcase.context.Output = out
err := PluginWrite(testcase.context, plugins) err := PluginWrite(testcase.context, plugins)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -56,7 +56,7 @@ id_rsa
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
testcase.context.Output = out testcase.context.Output = out
if err := SecretWrite(testcase.context, secrets); err != nil { if err := SecretWrite(testcase.context, secrets); err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -126,7 +126,7 @@ bar
testcase.context.Output = out testcase.context.Output = out
err := ServiceListWrite(testcase.context, services, info) err := ServiceListWrite(testcase.context, services, info)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -117,7 +117,7 @@ container2 --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "linux", false) err := ContainerStatsWrite(te.context, stats, "linux", false)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, te.expected)) assert.Error(t, err, te.expected)
} else { } else {
assert.Check(t, is.Equal(te.expected, out.String())) assert.Check(t, is.Equal(te.expected, out.String()))
} }
@ -183,7 +183,7 @@ container2 -- --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "windows", false) err := ContainerStatsWrite(te.context, stats, "windows", false)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, te.expected)) assert.Error(t, err, te.expected)
} else { } else {
assert.Check(t, is.Equal(te.expected, out.String())) assert.Check(t, is.Equal(te.expected, out.String()))
} }

View File

@ -75,7 +75,7 @@ foobar_bar foo2
testcase.context.Output = out testcase.context.Output = out
err := TaskWrite(testcase.context, tasks, names, nodes) err := TaskWrite(testcase.context, tasks, names, nodes)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -127,7 +127,7 @@ tag3 bbbbbbbb
testcase.context.Output = out testcase.context.Output = out
err := TrustTagWrite(testcase.context, signedTags) err := TrustTagWrite(testcase.context, signedTags)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
@ -231,7 +231,7 @@ eve foobarbazquxquux, key31, key32
testcase.context.Output = out testcase.context.Output = out
err := SignerInfoWrite(testcase.context, signerInfo) err := SignerInfoWrite(testcase.context, signerInfo)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -133,7 +133,7 @@ foobar_bar
testcase.context.Output = out testcase.context.Output = out
err := VolumeWrite(testcase.context, volumes) err := VolumeWrite(testcase.context, volumes)
if err != nil { if err != nil {
assert.Check(t, is.Error(err, testcase.expected)) assert.Error(t, err, testcase.expected)
} else { } else {
assert.Check(t, is.Equal(testcase.expected, out.String())) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }

View File

@ -22,7 +22,7 @@ func TestResolveError(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID") _, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
assert.Check(t, is.Error(err, "unsupported type")) assert.Error(t, err, "unsupported type")
} }
func TestResolveWithNoResolveOption(t *testing.T) { func TestResolveWithNoResolveOption(t *testing.T) {

View File

@ -9,7 +9,6 @@ import (
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/passphrase" "github.com/theupdateframework/notary/passphrase"
"github.com/theupdateframework/notary/trustpinning" "github.com/theupdateframework/notary/trustpinning"
@ -71,5 +70,5 @@ func TestAddTargetToAllSignableRolesError(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
target := client.Target{} target := client.Target{}
err = AddTargetToAllSignableRoles(notaryRepo, &target) err = AddTargetToAllSignableRoles(notaryRepo, &target)
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }

View File

@ -89,7 +89,7 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err = cmd.Execute() err = cmd.Execute()
assert.Check(t, is.Error(err, "refusing to amend an existing manifest list with no --amend flag")) assert.Error(t, err, "refusing to amend an existing manifest list with no --amend flag")
} }
// attempt to make a manifest list without valid images // attempt to make a manifest list without valid images
@ -112,5 +112,5 @@ func TestManifestCreateNoManifest(t *testing.T) {
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err := cmd.Execute() err := cmd.Execute()
assert.Check(t, is.Error(err, "No such image: example.com/alpine:3.0")) assert.Error(t, err, "No such image: example.com/alpine:3.0")
} }

View File

@ -15,7 +15,7 @@ import (
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -65,7 +65,7 @@ func TestInspectCommandLocalManifestNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
err := cmd.Execute() err := cmd.Execute()
assert.Check(t, is.Error(err, "No such manifest: example.com/alpine:3.0")) assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
} }
func TestInspectCommandNotFound(t *testing.T) { func TestInspectCommandNotFound(t *testing.T) {
@ -87,7 +87,7 @@ func TestInspectCommandNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/alpine:3.0"})
err := cmd.Execute() err := cmd.Execute()
assert.Check(t, is.Error(err, "No such manifest: example.com/alpine:3.0")) assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
} }
func TestInspectCommandLocalManifest(t *testing.T) { func TestInspectCommandLocalManifest(t *testing.T) {

View File

@ -49,7 +49,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), tc.expectedError)) assert.Error(t, cmd.Execute(), tc.expectedError)
} }
} }

View File

@ -13,7 +13,6 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
) )
@ -61,7 +60,7 @@ func TestNodePsErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), tc.expectedError)) assert.Error(t, cmd.Execute(), tc.expectedError)
} }
} }

View File

@ -74,6 +74,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
cmd := newSecretRemoveCommand(cli) cmd := newSecretRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.Check(t, is.Error(cmd.Execute(), "error removing secret: foo")) assert.Error(t, cmd.Execute(), "error removing secret: foo")
assert.Check(t, is.DeepEqual(names, removedSecrets)) assert.Check(t, is.DeepEqual(names, removedSecrets))
} }

View File

@ -88,7 +88,7 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
_, err := opt.toHealthConfig() _, err := opt.toHealthConfig()
assert.Check(t, is.Error(err, "--no-healthcheck conflicts with --health-* options")) assert.Error(t, err, "--no-healthcheck conflicts with --health-* options")
} }
func TestResourceOptionsToResourceRequirements(t *testing.T) { func TestResourceOptionsToResourceRequirements(t *testing.T) {

View File

@ -60,7 +60,7 @@ func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) {
filter: opts.NewFilterOpt(), filter: opts.NewFilterOpt(),
} }
_, _, err := createFilter(context.Background(), client, options) _, _, err := createFilter(context.Background(), client, options)
assert.Check(t, is.Error(err, "multiple services found with provided prefix: aaa")) assert.Error(t, err, "multiple services found with provided prefix: aaa")
} }
func TestCreateFilterNoneFound(t *testing.T) { func TestCreateFilterNoneFound(t *testing.T) {
@ -70,7 +70,7 @@ func TestCreateFilterNoneFound(t *testing.T) {
filter: opts.NewFilterOpt(), filter: opts.NewFilterOpt(),
} }
_, _, err := createFilter(context.Background(), client, options) _, _, err := createFilter(context.Background(), client, options)
assert.Check(t, is.Error(err, "no such service: foo\nno such service: notfound")) assert.Error(t, err, "no such service: foo\nno such service: notfound")
} }
func TestRunPSWarnsOnNotFound(t *testing.T) { func TestRunPSWarnsOnNotFound(t *testing.T) {
@ -89,7 +89,7 @@ func TestRunPSWarnsOnNotFound(t *testing.T) {
format: "{{.ID}}", format: "{{.ID}}",
} }
err := runPS(cli, options) err := runPS(cli, options)
assert.Check(t, is.Error(err, "no such service: bar")) assert.Error(t, err, "no such service: bar")
} }
func TestRunPSQuiet(t *testing.T) { func TestRunPSQuiet(t *testing.T) {

View File

@ -344,7 +344,7 @@ func TestUpdateHealthcheckTable(t *testing.T) {
} }
err := updateHealthcheck(flags, cspec) err := updateHealthcheck(flags, cspec)
if c.err != "" { if c.err != "" {
assert.Check(t, is.Error(err, c.err)) assert.Error(t, err, c.err)
} else { } else {
assert.NilError(t, err) assert.NilError(t, err)
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { if !reflect.DeepEqual(cspec.Healthcheck, c.expected) {
@ -626,14 +626,14 @@ func TestUpdateNetworks(t *testing.T) {
err = flags.Set(flagNetworkAdd, "aaa-network") err = flags.Set(flagNetworkAdd, "aaa-network")
assert.NilError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.Check(t, is.Error(err, "service is already attached to network aaa-network")) assert.Error(t, err, "service is already attached to network aaa-network")
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
err = flags.Set(flagNetworkAdd, "id555") err = flags.Set(flagNetworkAdd, "id555")
assert.NilError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.Check(t, is.Error(err, "service is already attached to network id555")) assert.Error(t, err, "service is already attached to network id555")
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()

View File

@ -61,7 +61,7 @@ func TestStackPsEmptyStack(t *testing.T) {
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), "nothing found in stack: foo")) assert.Error(t, cmd.Execute(), "nothing found in stack: foo")
assert.Check(t, is.Equal("", fakeCli.OutBuffer().String())) assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
} }

View File

@ -150,7 +150,7 @@ func TestRemoveContinueAfterError(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.Check(t, is.Error(cmd.Execute(), "Failed to remove some resources from stack: foo")) assert.Error(t, cmd.Execute(), "Failed to remove some resources from stack: foo")
assert.Check(t, is.DeepEqual(allServiceIDs, removedServices)) assert.Check(t, is.DeepEqual(allServiceIDs, removedServices))
assert.Check(t, is.DeepEqual(allNetworkIDs, cli.removedNetworks)) assert.Check(t, is.DeepEqual(allNetworkIDs, cli.removedNetworks))
assert.Check(t, is.DeepEqual(allSecretIDs, cli.removedSecrets)) assert.Check(t, is.DeepEqual(allSecretIDs, cli.removedSecrets))

View File

@ -34,7 +34,7 @@ func swarmSpecWithFullCAConfig() *swarm.Spec {
func TestDisplayTrustRootNoRoot(t *testing.T) { func TestDisplayTrustRootNoRoot(t *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
err := displayTrustRoot(buffer, swarm.Swarm{}) err := displayTrustRoot(buffer, swarm.Swarm{})
assert.Check(t, is.Error(err, "No CA information available")) assert.Error(t, err, "No CA information available")
} }
func TestDisplayTrustRootInvalidFlags(t *testing.T) { func TestDisplayTrustRootInvalidFlags(t *testing.T) {

View File

@ -9,7 +9,6 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -75,7 +74,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), tc.expectedError)) assert.Error(t, cmd.Execute(), tc.expectedError)
} }
} }

View File

@ -34,7 +34,7 @@ func TestNodeAddrOptionSetPortOnly(t *testing.T) {
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) { func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
opt := NewListenAddrOption() opt := NewListenAddrOption()
assert.Check(t, is.Error(opt.Set("http://localhost:4545"), "Invalid proto, expected tcp: http://localhost:4545")) assert.Error(t, opt.Set("http://localhost:4545"), "Invalid proto, expected tcp: http://localhost:4545")
} }
func TestExternalCAOptionErrors(t *testing.T) { func TestExternalCAOptionErrors(t *testing.T) {
@ -65,7 +65,7 @@ func TestExternalCAOptionErrors(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
opt := &ExternalCAOption{} opt := &ExternalCAOption{}
assert.Check(t, is.Error(opt.Set(tc.externalCA), tc.expectedError)) assert.Error(t, opt.Set(tc.externalCA), tc.expectedError)
} }
} }

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/passphrase" "github.com/theupdateframework/notary/passphrase"
"github.com/theupdateframework/notary/trustpinning" "github.com/theupdateframework/notary/trustpinning"
@ -21,5 +20,5 @@ func TestGetOrGenerateNotaryKeyAndInitRepo(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
err = getOrGenerateRootKeyAndInitRepo(notaryRepo) err = getOrGenerateRootKeyAndInitRepo(notaryRepo)
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }

View File

@ -143,5 +143,5 @@ func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
target := client.Target{} target := client.Target{}
err = getSignableRolesForTargetAndRemove(target, notaryRepo) err = getSignableRolesForTargetAndRemove(target, notaryRepo)
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }

View File

@ -220,7 +220,7 @@ func TestGetSignedManifestHashAndSize(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
target := &client.Target{} target := &client.Target{}
target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test") target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }
func TestGetReleasedTargetHashAndSize(t *testing.T) { func TestGetReleasedTargetHashAndSize(t *testing.T) {
@ -231,7 +231,7 @@ func TestGetReleasedTargetHashAndSize(t *testing.T) {
oneReleasedTgt = append(oneReleasedTgt, client.TargetSignedStruct{Role: mockDelegationRoleWithName(unreleasedRole), Target: unreleasedTgt}) oneReleasedTgt = append(oneReleasedTgt, client.TargetSignedStruct{Role: mockDelegationRoleWithName(unreleasedRole), Target: unreleasedTgt})
} }
_, _, err := getReleasedTargetHashAndSize(oneReleasedTgt, "unreleased") _, _, err := getReleasedTargetHashAndSize(oneReleasedTgt, "unreleased")
assert.Check(t, is.Error(err, "No valid trust data for unreleased")) assert.Error(t, err, "No valid trust data for unreleased")
releasedTgt := client.Target{Name: "released", Hashes: data.Hashes{notary.SHA256: []byte("released-hash")}} releasedTgt := client.Target{Name: "released", Hashes: data.Hashes{notary.SHA256: []byte("released-hash")}}
oneReleasedTgt = append(oneReleasedTgt, client.TargetSignedStruct{Role: mockDelegationRoleWithName("targets/releases"), Target: releasedTgt}) oneReleasedTgt = append(oneReleasedTgt, client.TargetSignedStruct{Role: mockDelegationRoleWithName("targets/releases"), Target: releasedTgt})
hash, _, _ := getReleasedTargetHashAndSize(oneReleasedTgt, "unreleased") hash, _, _ := getReleasedTargetHashAndSize(oneReleasedTgt, "unreleased")
@ -247,9 +247,9 @@ func TestCreateTarget(t *testing.T) {
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.NilError(t, err) assert.NilError(t, err)
_, err = createTarget(notaryRepo, "") _, err = createTarget(notaryRepo, "")
assert.Check(t, is.Error(err, "No tag specified")) assert.Error(t, err, "No tag specified")
_, err = createTarget(notaryRepo, "1") _, err = createTarget(notaryRepo, "1")
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }
func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) { func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) {
@ -260,7 +260,7 @@ func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) {
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.NilError(t, err) assert.NilError(t, err)
_, err = getExistingSignatureInfoForReleasedTag(notaryRepo, "test") _, err = getExistingSignatureInfoForReleasedTag(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }
func TestPrettyPrintExistingSignatureInfo(t *testing.T) { func TestPrettyPrintExistingSignatureInfo(t *testing.T) {

View File

@ -81,7 +81,7 @@ func TestSignerAddCommandNoTargetsKey(t *testing.T) {
cmd.SetArgs([]string{"--key", tmpfile.Name(), "alice", "alpine", "linuxkit/alpine"}) cmd.SetArgs([]string{"--key", tmpfile.Name(), "alice", "alpine", "linuxkit/alpine"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))) assert.Error(t, cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
} }
func TestSignerAddCommandBadKeyPath(t *testing.T) { func TestSignerAddCommandBadKeyPath(t *testing.T) {
@ -96,7 +96,7 @@ func TestSignerAddCommandBadKeyPath(t *testing.T) {
cmd.SetArgs([]string{"--key", "/path/to/key.pem", "alice", "alpine"}) cmd.SetArgs([]string{"--key", "/path/to/key.pem", "alice", "alpine"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), "unable to read public key from file: open /path/to/key.pem: no such file or directory")) assert.Error(t, cmd.Execute(), "unable to read public key from file: open /path/to/key.pem: no such file or directory")
} }
func TestSignerAddCommandInvalidRepoName(t *testing.T) { func TestSignerAddCommandInvalidRepoName(t *testing.T) {
@ -118,7 +118,7 @@ func TestSignerAddCommandInvalidRepoName(t *testing.T) {
cmd.SetArgs([]string{"--key", pubKeyFilepath, "alice", imageName}) cmd.SetArgs([]string{"--key", pubKeyFilepath, "alice", imageName})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Check(t, is.Error(cmd.Execute(), "Failed to add signer to: 870d292919d01a0af7e7f056271dc78792c05f55f49b9b9012b6d89725bd9abd")) assert.Error(t, cmd.Execute(), "Failed to add signer to: 870d292919d01a0af7e7f056271dc78792c05f55f49b9b9012b6d89725bd9abd")
expectedErr := fmt.Sprintf("invalid repository name (%s), cannot specify 64-byte hexadecimal strings\n\n", imageName) expectedErr := fmt.Sprintf("invalid repository name (%s), cannot specify 64-byte hexadecimal strings\n\n", imageName)
assert.Check(t, is.Equal(expectedErr, cli.ErrBuffer().String())) assert.Check(t, is.Equal(expectedErr, cli.ErrBuffer().String()))
@ -127,11 +127,11 @@ func TestSignerAddCommandInvalidRepoName(t *testing.T) {
func TestIngestPublicKeys(t *testing.T) { func TestIngestPublicKeys(t *testing.T) {
// Call with a bad path // Call with a bad path
_, err := ingestPublicKeys([]string{"foo", "bar"}) _, err := ingestPublicKeys([]string{"foo", "bar"})
assert.Check(t, is.Error(err, "unable to read public key from file: open foo: no such file or directory")) assert.Error(t, err, "unable to read public key from file: open foo: no such file or directory")
// Call with real file path // Call with real file path
tmpfile, err := ioutil.TempFile("", "pemfile") tmpfile, err := ioutil.TempFile("", "pemfile")
assert.NilError(t, err) assert.NilError(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
_, err = ingestPublicKeys([]string{tmpfile.Name()}) _, err = ingestPublicKeys([]string{tmpfile.Name()})
assert.Check(t, is.Error(err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))) assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
} }

View File

@ -71,16 +71,16 @@ func TestRemoveSingleSigner(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{}) cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(getLoadedNotaryRepository) cli.SetNotaryClient(getLoadedNotaryRepository)
err := removeSingleSigner(cli, "signed-repo", "test", true) err := removeSingleSigner(cli, "signed-repo", "test", true)
assert.Check(t, is.Error(err, "No signer test for repository signed-repo")) assert.Error(t, err, "No signer test for repository signed-repo")
err = removeSingleSigner(cli, "signed-repo", "releases", true) err = removeSingleSigner(cli, "signed-repo", "releases", true)
assert.Check(t, is.Error(err, "releases is a reserved keyword and cannot be removed")) assert.Error(t, err, "releases is a reserved keyword and cannot be removed")
} }
func TestRemoveMultipleSigners(t *testing.T) { func TestRemoveMultipleSigners(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{}) cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(getLoadedNotaryRepository) cli.SetNotaryClient(getLoadedNotaryRepository)
err := removeSigner(cli, signerRemoveOptions{signer: "test", repos: []string{"signed-repo", "signed-repo"}, forceYes: true}) err := removeSigner(cli, signerRemoveOptions{signer: "test", repos: []string{"signed-repo", "signed-repo"}, forceYes: true})
assert.Check(t, is.Error(err, "Error removing signer from: signed-repo, signed-repo")) assert.Error(t, err, "Error removing signer from: signed-repo, signed-repo")
assert.Check(t, is.Contains(cli.ErrBuffer().String(), assert.Check(t, is.Contains(cli.ErrBuffer().String(),
"No signer test for repository signed-repo")) "No signer test for repository signed-repo"))
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Removing signer \"test\" from signed-repo...\n")) assert.Check(t, is.Contains(cli.OutBuffer().String(), "Removing signer \"test\" from signed-repo...\n"))

View File

@ -26,7 +26,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.Check(t, is.Error(err, "unknown restart policy: unknown")) assert.Error(t, err, "unknown restart policy: unknown")
} }
func TestConvertRestartPolicyFromAlways(t *testing.T) { func TestConvertRestartPolicyFromAlways(t *testing.T) {
@ -161,7 +161,7 @@ func TestConvertHealthcheckDisableWithTest(t *testing.T) {
Test: []string{"EXEC", "touch"}, Test: []string{"EXEC", "touch"},
} }
_, err := convertHealthcheck(source) _, err := convertHealthcheck(source)
assert.Check(t, is.Error(err, "test and disable can't be set at the same time")) assert.Error(t, err, "test and disable can't be set at the same time")
} }
func TestConvertEndpointSpec(t *testing.T) { func TestConvertEndpointSpec(t *testing.T) {

View File

@ -32,7 +32,7 @@ func TestConvertVolumeToMountAnonymousBind(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) _, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Check(t, is.Error(err, "invalid bind source, source cannot be empty")) assert.Error(t, err, "invalid bind source, source cannot be empty")
} }
func TestConvertVolumeToMountUnapprovedType(t *testing.T) { func TestConvertVolumeToMountUnapprovedType(t *testing.T) {
@ -41,7 +41,7 @@ func TestConvertVolumeToMountUnapprovedType(t *testing.T) {
Target: "/foo/bar", Target: "/foo/bar",
} }
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) _, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Check(t, is.Error(err, "volume type must be volume, bind, or tmpfs")) assert.Error(t, err, "volume type must be volume, bind, or tmpfs")
} }
func TestConvertVolumeToMountConflictingOptionsBindInVolume(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsBindInVolume(t *testing.T) {
@ -56,7 +56,7 @@ func TestConvertVolumeToMountConflictingOptionsBindInVolume(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "bind options are incompatible with type volume")) assert.Error(t, err, "bind options are incompatible with type volume")
} }
func TestConvertVolumeToMountConflictingOptionsTmpfsInVolume(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsTmpfsInVolume(t *testing.T) {
@ -71,7 +71,7 @@ func TestConvertVolumeToMountConflictingOptionsTmpfsInVolume(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "tmpfs options are incompatible with type volume")) assert.Error(t, err, "tmpfs options are incompatible with type volume")
} }
func TestConvertVolumeToMountConflictingOptionsVolumeInBind(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsVolumeInBind(t *testing.T) {
@ -86,7 +86,7 @@ func TestConvertVolumeToMountConflictingOptionsVolumeInBind(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "volume options are incompatible with type bind")) assert.Error(t, err, "volume options are incompatible with type bind")
} }
func TestConvertVolumeToMountConflictingOptionsTmpfsInBind(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsTmpfsInBind(t *testing.T) {
@ -101,7 +101,7 @@ func TestConvertVolumeToMountConflictingOptionsTmpfsInBind(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "tmpfs options are incompatible with type bind")) assert.Error(t, err, "tmpfs options are incompatible with type bind")
} }
func TestConvertVolumeToMountConflictingOptionsBindInTmpfs(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsBindInTmpfs(t *testing.T) {
@ -115,7 +115,7 @@ func TestConvertVolumeToMountConflictingOptionsBindInTmpfs(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "bind options are incompatible with type tmpfs")) assert.Error(t, err, "bind options are incompatible with type tmpfs")
} }
func TestConvertVolumeToMountConflictingOptionsVolumeInTmpfs(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsVolumeInTmpfs(t *testing.T) {
@ -129,7 +129,7 @@ func TestConvertVolumeToMountConflictingOptionsVolumeInTmpfs(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "volume options are incompatible with type tmpfs")) assert.Error(t, err, "volume options are incompatible with type tmpfs")
} }
func TestConvertVolumeToMountNamedVolume(t *testing.T) { func TestConvertVolumeToMountNamedVolume(t *testing.T) {
@ -309,7 +309,7 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
ReadOnly: true, ReadOnly: true,
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Check(t, is.Error(err, "undefined volume \"unknown\"")) assert.Error(t, err, "undefined volume \"unknown\"")
} }
func TestConvertTmpfsToMountVolume(t *testing.T) { func TestConvertTmpfsToMountVolume(t *testing.T) {
@ -341,5 +341,5 @@ func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) {
} }
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) _, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Check(t, is.Error(err, "invalid tmpfs source, source must be empty")) assert.Error(t, err, "invalid tmpfs source, source must be empty")
} }

View File

@ -58,7 +58,7 @@ func TestInvalidInterpolation(t *testing.T) {
}, },
} }
_, err := Interpolate(services, Options{LookupValue: defaultMapping}) _, err := Interpolate(services, Options{LookupValue: defaultMapping})
assert.Check(t, is.Error(err, `invalid interpolation format for servicea.image: "${". You may need to escape any $ with another $.`)) assert.Error(t, err, `invalid interpolation format for servicea.image: "${". You may need to escape any $ with another $.`)
} }
func TestInterpolateWithDefaults(t *testing.T) { func TestInterpolateWithDefaults(t *testing.T) {

View File

@ -29,7 +29,7 @@ func TestParseVolumeAnonymousVolumeWindows(t *testing.T) {
func TestParseVolumeTooManyColons(t *testing.T) { func TestParseVolumeTooManyColons(t *testing.T) {
_, err := ParseVolume("/foo:/foo:ro:foo") _, err := ParseVolume("/foo:/foo:ro:foo")
assert.Check(t, is.Error(err, "invalid spec: /foo:/foo:ro:foo: too many colons")) assert.Error(t, err, "invalid spec: /foo:/foo:ro:foo: too many colons")
} }
func TestParseVolumeShortVolumes(t *testing.T) { func TestParseVolumeShortVolumes(t *testing.T) {

View File

@ -96,7 +96,7 @@ func TestStoreSaveAndGet(t *testing.T) {
t.Run(testcase.manifestRef.String(), func(t *testing.T) { t.Run(testcase.manifestRef.String(), func(t *testing.T) {
actual, err := store.Get(testcase.listRef, testcase.manifestRef) actual, err := store.Get(testcase.listRef, testcase.manifestRef)
if testcase.expectedErr != "" { if testcase.expectedErr != "" {
assert.Check(t, is.Error(err, testcase.expectedErr)) assert.Error(t, err, testcase.expectedErr)
assert.Check(t, IsNotFound(err)) assert.Check(t, IsNotFound(err))
return return
} }
@ -131,6 +131,6 @@ func TestStoreGetListDoesNotExist(t *testing.T) {
listRef := ref("list") listRef := ref("list")
_, err := store.GetList(listRef) _, err := store.GetList(listRef)
assert.Check(t, is.Error(err, "No such manifest: list")) assert.Error(t, err, "No such manifest: list")
assert.Check(t, IsNotFound(err)) assert.Check(t, IsNotFound(err))
} }

View File

@ -57,5 +57,5 @@ func TestGetSignableRolesError(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
target := client.Target{} target := client.Target{}
_, err = GetSignableRoles(notaryRepo, &target) _, err = GetSignableRoles(notaryRepo, &target)
assert.Check(t, is.Error(err, "client is offline")) assert.Error(t, err, "client is offline")
} }

View File

@ -29,5 +29,5 @@ func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard)) cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
cmd.SetArgs([]string{"help", "invalid"}) cmd.SetArgs([]string{"help", "invalid"})
err := cmd.Execute() err := cmd.Execute()
assert.Check(t, is.Error(err, "unknown help topic: invalid")) assert.Error(t, err, "unknown help topic: invalid")
} }

View File

@ -26,5 +26,5 @@ func TestPositiveDurationOptSetAndValue(t *testing.T) {
var duration PositiveDurationOpt var duration PositiveDurationOpt
assert.NilError(t, duration.Set("300s")) assert.NilError(t, duration.Set("300s"))
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value())) assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
assert.Check(t, is.Error(duration.Set("-300s"), "duration cannot be negative")) assert.Error(t, duration.Set("-300s"), "duration cannot be negative")
} }

View File

@ -82,23 +82,23 @@ func TestMountOptDefaultType(t *testing.T) {
func TestMountOptSetErrorNoTarget(t *testing.T) { func TestMountOptSetErrorNoTarget(t *testing.T) {
var mount MountOpt var mount MountOpt
assert.Check(t, is.Error(mount.Set("type=volume,source=/foo"), "target is required")) assert.Error(t, mount.Set("type=volume,source=/foo"), "target is required")
} }
func TestMountOptSetErrorInvalidKey(t *testing.T) { func TestMountOptSetErrorInvalidKey(t *testing.T) {
var mount MountOpt var mount MountOpt
assert.Check(t, is.Error(mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus' in 'bogus=foo'")) assert.Error(t, mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus' in 'bogus=foo'")
} }
func TestMountOptSetErrorInvalidField(t *testing.T) { func TestMountOptSetErrorInvalidField(t *testing.T) {
var mount MountOpt var mount MountOpt
assert.Check(t, is.Error(mount.Set("type=volume,bogus"), "invalid field 'bogus' must be a key=value pair")) assert.Error(t, mount.Set("type=volume,bogus"), "invalid field 'bogus' must be a key=value pair")
} }
func TestMountOptSetErrorInvalidReadOnly(t *testing.T) { func TestMountOptSetErrorInvalidReadOnly(t *testing.T) {
var mount MountOpt var mount MountOpt
assert.Check(t, is.Error(mount.Set("type=volume,readonly=no"), "invalid value for readonly: no")) assert.Error(t, mount.Set("type=volume,readonly=no"), "invalid value for readonly: no")
assert.Check(t, is.Error(mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid")) assert.Error(t, mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid")
} }
func TestMountOptDefaultEnableReadOnly(t *testing.T) { func TestMountOptDefaultEnableReadOnly(t *testing.T) {

View File

@ -278,7 +278,7 @@ func TestPortOptInvalidSimpleSyntax(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
var port PortOpt var port PortOpt
assert.Check(t, is.Error(port.Set(tc.value), tc.expectedError)) assert.Error(t, port.Set(tc.value), tc.expectedError)
} }
} }

View File

@ -25,7 +25,7 @@ func TestParseLogDetails(t *testing.T) {
t.Run(testcase.line, func(t *testing.T) { t.Run(testcase.line, func(t *testing.T) {
actual, err := ParseLogDetails(testcase.line) actual, err := ParseLogDetails(testcase.line)
if testcase.err != nil { if testcase.err != nil {
assert.Check(t, is.Error(err, testcase.err.Error())) assert.Error(t, err, testcase.err.Error())
return return
} }
assert.Check(t, is.DeepEqual(testcase.expected, actual)) assert.Check(t, is.DeepEqual(testcase.expected, actual))