[#34] Add tests to commands expecting N args
Commands using cobra's ExactArgs feature previously did not have any validation that the ExactArgs was being enforced. This patchset adds tests to ensure that in the cases ExactArgs=n, that only n args are accepted, and other values such as x or y throw an appropriate error. Change-Id: I27b5774e79db51e0e9bc81d8c207be80811ba459
This commit is contained in:
@@ -18,6 +18,7 @@ package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
kubeconfig "k8s.io/client-go/tools/clientcmd/api"
|
||||
@@ -50,6 +51,18 @@ func TestConfigSetContext(t *testing.T) {
|
||||
CmdLine: "--help",
|
||||
Cmd: NewCmdConfigSetContext(nil),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-context-too-many-args",
|
||||
CmdLine: "arg1 arg2",
|
||||
Cmd: NewCmdConfigSetContext(nil),
|
||||
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 2),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-context-too-few-args",
|
||||
CmdLine: "",
|
||||
Cmd: NewCmdConfigSetContext(nil),
|
||||
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cmdTests {
|
||||
|
||||
Reference in New Issue
Block a user