mirror of https://github.com/docker/cli.git
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The functions are extremely similar to testify, but with enough slight differences to be confusing (for example, Equal takes its arguments in a different order). We already vendor testify, and it's used in a few places by tests. I also found some problems with pkg/testutil/assert. For example, the NotNil function seems to be broken. It checks the argument against "nil", which only works for an interface. If you pass in a nil map or slice, the equality check will fail. In the interest of avoiding NIH, I'm proposing replacing pkg/testutil/assert with testify. The test code looks almost the same, but we avoid the confusion of having two similar but slightly different assertion packages, and having to maintain our own package instead of using a commonly-used one. In the process, I found a few places where the tests should halt if an assertion fails, so I've made those cases (that I noticed) use "require" instead of "assert", and I've vendored the "require" package from testify alongside the already-present "assert" package. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
db8f631c1f
commit
6029def4cb
|
@ -5,7 +5,7 @@ package main
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDaemonCommand(t *testing.T) {
|
||||
|
@ -13,5 +13,5 @@ func TestDaemonCommand(t *testing.T) {
|
|||
cmd.SetArgs([]string{"--version"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.Error(t, err, "Please run `dockerd`")
|
||||
assert.EqualError(t, err, "Please run `dockerd`")
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ package main
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func stubRun(cmd *cobra.Command, args []string) error {
|
||||
|
@ -18,7 +18,7 @@ func TestDaemonCommandHelp(t *testing.T) {
|
|||
cmd.RunE = stubRun
|
||||
cmd.SetArgs([]string{"--help"})
|
||||
err := cmd.Execute()
|
||||
assert.NilError(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDaemonCommand(t *testing.T) {
|
||||
|
@ -26,5 +26,5 @@ func TestDaemonCommand(t *testing.T) {
|
|||
cmd.RunE = stubRun
|
||||
cmd.SetArgs([]string{"--containerd", "/foo"})
|
||||
err := cmd.Execute()
|
||||
assert.NilError(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClientDebugEnabled(t *testing.T) {
|
||||
|
@ -18,9 +18,9 @@ func TestClientDebugEnabled(t *testing.T) {
|
|||
cmd.Flags().Set("debug", "true")
|
||||
|
||||
err := cmd.PersistentPreRunE(cmd, []string{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, os.Getenv("DEBUG"), "1")
|
||||
assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", os.Getenv("DEBUG"))
|
||||
assert.Equal(t, logrus.DebugLevel, logrus.GetLevel())
|
||||
}
|
||||
|
||||
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
||||
|
@ -28,5 +28,5 @@ func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
|||
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
|
||||
cmd.SetArgs([]string{"help", "invalid"})
|
||||
err := cmd.Execute()
|
||||
assert.Error(t, err, "unknown help topic: invalid")
|
||||
assert.EqualError(t, err, "unknown help topic: invalid")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue