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>
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
package image
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli/internal/test"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/pkg/testutil"
|
|
"github.com/pkg/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewPushCommandErrors(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
args []string
|
|
expectedError string
|
|
imagePushFunc func(ref string, options types.ImagePushOptions) (io.ReadCloser, error)
|
|
}{
|
|
{
|
|
name: "wrong-args",
|
|
args: []string{},
|
|
expectedError: "requires exactly 1 argument.",
|
|
},
|
|
{
|
|
name: "invalid-name",
|
|
args: []string{"UPPERCASE_REPO"},
|
|
expectedError: "invalid reference format: repository name must be lowercase",
|
|
},
|
|
{
|
|
name: "push-failed",
|
|
args: []string{"image:repo"},
|
|
expectedError: "Failed to push",
|
|
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
|
return ioutil.NopCloser(strings.NewReader("")), errors.Errorf("Failed to push")
|
|
},
|
|
},
|
|
{
|
|
name: "trust-error",
|
|
args: []string{"--disable-content-trust=false", "image:repo"},
|
|
expectedError: "you are not authorized to perform this operation: server returned 401.",
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
cli := test.NewFakeCli(&fakeClient{imagePushFunc: tc.imagePushFunc})
|
|
cmd := NewPushCommand(cli)
|
|
cmd.SetOutput(ioutil.Discard)
|
|
cmd.SetArgs(tc.args)
|
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
|
}
|
|
}
|
|
|
|
func TestNewPushCommandSuccess(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
args []string
|
|
}{
|
|
{
|
|
name: "simple",
|
|
args: []string{"image:tag"},
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
|
return ioutil.NopCloser(strings.NewReader("")), nil
|
|
},
|
|
})
|
|
cmd := NewPushCommand(cli)
|
|
cmd.SetOutput(ioutil.Discard)
|
|
cmd.SetArgs(tc.args)
|
|
assert.NoError(t, cmd.Execute())
|
|
}
|
|
}
|