Merge pull request #14161 from feihujiang/letKubectlExecFollowDashRule
Auto commit by PR queue bot
This commit is contained in:
@@ -48,6 +48,7 @@ func (f *fakeRemoteExecutor) Execute(method string, url *url.URL, config *client
|
||||
func TestPodAndContainer(t *testing.T) {
|
||||
tests := []struct {
|
||||
args []string
|
||||
argsLenAtDash int
|
||||
p *ExecOptions
|
||||
name string
|
||||
expectError bool
|
||||
@@ -56,43 +57,65 @@ func TestPodAndContainer(t *testing.T) {
|
||||
expectedArgs []string
|
||||
}{
|
||||
{
|
||||
p: &ExecOptions{},
|
||||
expectError: true,
|
||||
name: "empty",
|
||||
p: &ExecOptions{},
|
||||
argsLenAtDash: -1,
|
||||
expectError: true,
|
||||
name: "empty",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{PodName: "foo"},
|
||||
expectError: true,
|
||||
name: "no cmd",
|
||||
p: &ExecOptions{PodName: "foo"},
|
||||
argsLenAtDash: -1,
|
||||
expectError: true,
|
||||
name: "no cmd",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{PodName: "foo", ContainerName: "bar"},
|
||||
expectError: true,
|
||||
name: "no cmd, w/ container",
|
||||
p: &ExecOptions{PodName: "foo", ContainerName: "bar"},
|
||||
argsLenAtDash: -1,
|
||||
expectError: true,
|
||||
name: "no cmd, w/ container",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{PodName: "foo"},
|
||||
args: []string{"cmd"},
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "pod in flags",
|
||||
p: &ExecOptions{PodName: "foo"},
|
||||
args: []string{"cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "pod in flags",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo"},
|
||||
expectError: true,
|
||||
name: "no cmd, w/o flags",
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: 0,
|
||||
expectError: true,
|
||||
name: "no pod, pod name is behind dash",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo", "cmd"},
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "cmd, w/o flags",
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo"},
|
||||
argsLenAtDash: -1,
|
||||
expectError: true,
|
||||
name: "no cmd, w/o flags",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "cmd, w/o flags",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: 1,
|
||||
expectedPod: "foo",
|
||||
expectedArgs: []string{"cmd"},
|
||||
name: "cmd, cmd is behind dash",
|
||||
},
|
||||
{
|
||||
p: &ExecOptions{ContainerName: "bar"},
|
||||
args: []string{"foo", "cmd"},
|
||||
argsLenAtDash: -1,
|
||||
expectedPod: "foo",
|
||||
expectedContainer: "bar",
|
||||
expectedArgs: []string{"cmd"},
|
||||
@@ -110,7 +133,7 @@ func TestPodAndContainer(t *testing.T) {
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
options := test.p
|
||||
err := options.Complete(f, cmd, test.args)
|
||||
err := options.Complete(f, cmd, test.args, test.argsLenAtDash)
|
||||
if test.expectError && err == nil {
|
||||
t.Errorf("unexpected non-error (%s)", test.name)
|
||||
}
|
||||
@@ -189,7 +212,8 @@ func TestExec(t *testing.T) {
|
||||
Executor: ex,
|
||||
}
|
||||
cmd := &cobra.Command{}
|
||||
if err := params.Complete(f, cmd, []string{"test", "command"}); err != nil {
|
||||
args := []string{"test", "command"}
|
||||
if err := params.Complete(f, cmd, args, -1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := params.Run()
|
||||
|
||||
Reference in New Issue
Block a user