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
5084e4d6b4
commit
50e74272d1
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestContainersPruneError(t *testing.T) {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
_, err := client.ContainersPrune(context.Background(), filters)
|
_, err := client.ContainersPrune(context.Background(), filters)
|
||||||
assert.Error(t, err, "Error response from daemon: Server error")
|
assert.EqualError(t, err, "Error response from daemon: Server error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainersPrune(t *testing.T) {
|
func TestContainersPrune(t *testing.T) {
|
||||||
|
@ -99,7 +99,7 @@ func TestContainersPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.ContainersPruneReport{
|
content, err := json.Marshal(types.ContainersPruneReport{
|
||||||
ContainersDeleted: []string{"container_id1", "container_id2"},
|
ContainersDeleted: []string{"container_id1", "container_id2"},
|
||||||
|
@ -117,8 +117,8 @@ func TestContainersPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.ContainersPrune(context.Background(), listCase.filters)
|
report, err := client.ContainersPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.ContainersDeleted), 2)
|
assert.Len(t, report.ContainersDeleted, 2)
|
||||||
assert.Equal(t, report.SpaceReclaimed, uint64(9999))
|
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestImagesPruneError(t *testing.T) {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
_, err := client.ImagesPrune(context.Background(), filters)
|
_, err := client.ImagesPrune(context.Background(), filters)
|
||||||
assert.Error(t, err, "Error response from daemon: Server error")
|
assert.EqualError(t, err, "Error response from daemon: Server error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImagesPrune(t *testing.T) {
|
func TestImagesPrune(t *testing.T) {
|
||||||
|
@ -87,7 +87,7 @@ func TestImagesPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.ImagesPruneReport{
|
content, err := json.Marshal(types.ImagesPruneReport{
|
||||||
ImagesDeleted: []types.ImageDeleteResponseItem{
|
ImagesDeleted: []types.ImageDeleteResponseItem{
|
||||||
|
@ -112,8 +112,8 @@ func TestImagesPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.ImagesPrune(context.Background(), listCase.filters)
|
report, err := client.ImagesPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.ImagesDeleted), 2)
|
assert.Len(t, report.ImagesDeleted, 2)
|
||||||
assert.Equal(t, report.SpaceReclaimed, uint64(9999))
|
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.NetworksPruneReport{
|
content, err := json.Marshal(types.NetworksPruneReport{
|
||||||
NetworksDeleted: []string{"network_id1", "network_id2"},
|
NetworksDeleted: []string{"network_id1", "network_id2"},
|
||||||
|
@ -106,7 +106,7 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.NetworksPrune(context.Background(), listCase.filters)
|
report, err := client.NetworksPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.NetworksDeleted), 2)
|
assert.Len(t, report.NetworksDeleted, 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue