mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #5860 from brendandburns/kubecfg
Add validation of args for create.
This commit is contained in:
commit
ada4f5a366
@ -46,14 +46,21 @@ func (f *Factory) NewCmdCreate(out io.Writer) *cobra.Command {
|
|||||||
Long: create_long,
|
Long: create_long,
|
||||||
Example: create_example,
|
Example: create_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := RunCreate(f, out, cmd, filenames)
|
cmdutil.CheckErr(ValidateArgs(cmd, args))
|
||||||
cmdutil.CheckErr(err)
|
cmdutil.CheckErr(RunCreate(f, out, cmd, filenames))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().VarP(&filenames, "filename", "f", "Filename, directory, or URL to file to use to create the resource")
|
cmd.Flags().VarP(&filenames, "filename", "f", "Filename, directory, or URL to file to use to create the resource")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValidateArgs(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return cmdutil.UsageError(cmd, "Unexpected args: %v", args)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func RunCreate(f *Factory, out io.Writer, cmd *cobra.Command, filenames util.StringList) error {
|
func RunCreate(f *Factory, out io.Writer, cmd *cobra.Command, filenames util.StringList) error {
|
||||||
schema, err := f.Validator()
|
schema, err := f.Validator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -22,8 +22,19 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestExtraArgsFail(t *testing.T) {
|
||||||
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
|
f, _, _ := NewAPIFactory()
|
||||||
|
c := f.NewCmdCreate(buf)
|
||||||
|
if cmd.ValidateArgs(c, []string{"rc"}) == nil {
|
||||||
|
t.Errorf("unexpected non-error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateObject(t *testing.T) {
|
func TestCreateObject(t *testing.T) {
|
||||||
_, _, rc := testData()
|
_, _, rc := testData()
|
||||||
rc.Items[0].Name = "redis-master-controller"
|
rc.Items[0].Name = "redis-master-controller"
|
||||||
|
Loading…
Reference in New Issue
Block a user