The validation functions to test for the number of passed arguments did not
pluralize `argument(s)`, and used `argument(s)` in all cases.
This patch adds a simple `pluralize()` helper to improve this.
Before this change, `argument(s)` was used in all cases:
$ docker container ls foobar
"docker container ls" accepts no argument(s).
$ docker network create one two
"docker network create" requires exactly 1 argument(s).
$ docker network connect
"docker network connect" requires exactly 2 argument(s).
$ docker volume create one two
"docker volume create" requires at most 1 argument(s).
After this change, `argument(s)` is properly singularized or plurarized:
$ docker container ls foobar
"docker container ls" accepts no arguments.
$ docker network create one two
"docker network create" requires exactly 1 argument.
$ docker network connect
"docker network connect" requires exactly 2 arguments.
$ docker volume create one two
"docker volume create" requires at most 1 argument.
Test cases were updated accordingly.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package image
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli/internal/test"
|
|
"github.com/docker/docker/pkg/testutil"
|
|
"github.com/docker/docker/pkg/testutil/golden"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewPullCommandErrors(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
args []string
|
|
expectedError string
|
|
}{
|
|
{
|
|
name: "wrong-args",
|
|
expectedError: "requires exactly 1 argument.",
|
|
args: []string{},
|
|
},
|
|
{
|
|
name: "invalid-name",
|
|
expectedError: "invalid reference format: repository name must be lowercase",
|
|
args: []string{"UPPERCASE_REPO"},
|
|
},
|
|
{
|
|
name: "all-tags-with-tag",
|
|
expectedError: "tag can't be used with --all-tags/-a",
|
|
args: []string{"--all-tags", "image:tag"},
|
|
},
|
|
{
|
|
name: "pull-error",
|
|
args: []string{"--disable-content-trust=false", "image:tag"},
|
|
expectedError: "you are not authorized to perform this operation: server returned 401.",
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
cli := test.NewFakeCli(&fakeClient{})
|
|
cmd := NewPullCommand(cli)
|
|
cmd.SetOutput(ioutil.Discard)
|
|
cmd.SetArgs(tc.args)
|
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
|
}
|
|
}
|
|
|
|
func TestNewPullCommandSuccess(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
args []string
|
|
}{
|
|
{
|
|
name: "simple",
|
|
args: []string{"image:tag"},
|
|
},
|
|
{
|
|
name: "simple-no-tag",
|
|
args: []string{"image"},
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
cli := test.NewFakeCli(&fakeClient{})
|
|
cmd := NewPullCommand(cli)
|
|
cmd.SetOutput(ioutil.Discard)
|
|
cmd.SetArgs(tc.args)
|
|
err := cmd.Execute()
|
|
assert.NoError(t, err)
|
|
actual := cli.OutBuffer().String()
|
|
expected := string(golden.Get(t, []byte(actual), fmt.Sprintf("pull-command-success.%s.golden", tc.name))[:])
|
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, expected)
|
|
}
|
|
}
|