Merge "[#34] Add tests to commands expecting N args"

This commit is contained in:
Zuul 2020-02-12 14:41:12 +00:00 committed by Gerrit Code Review
commit 1399c569f4
9 changed files with 136 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package completion_test
import ( import (
"errors" "errors"
"fmt"
"testing" "testing"
"opendev.org/airship/airshipctl/cmd/completion" "opendev.org/airship/airshipctl/cmd/completion"
@ -9,25 +10,35 @@ import (
) )
func TestCompletion(t *testing.T) { func TestCompletion(t *testing.T) {
cmd := completion.NewCompletionCommand()
cmdTests := []*testutil.CmdTest{ cmdTests := []*testutil.CmdTest{
{ {
Name: "completion-bash", Name: "completion-bash",
CmdLine: "bash", CmdLine: "bash",
Cmd: cmd, Cmd: completion.NewCompletionCommand(),
}, },
{ {
Name: "completion-zsh", Name: "completion-zsh",
CmdLine: "zsh", CmdLine: "zsh",
Cmd: cmd, Cmd: completion.NewCompletionCommand(),
}, },
{ {
Name: "completion-unknown-shell", Name: "completion-unknown-shell",
CmdLine: "fish", CmdLine: "fish",
Cmd: cmd, Cmd: completion.NewCompletionCommand(),
Error: errors.New("unsupported shell type \"fish\""), Error: errors.New("unsupported shell type \"fish\""),
}, },
{
Name: "completion-cmd-too-many-args",
CmdLine: "arg1 arg2",
Cmd: completion.NewCompletionCommand(),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 2),
},
{
Name: "completion-cmd-too-few-args",
CmdLine: "",
Cmd: completion.NewCompletionCommand(),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
},
} }
for _, tt := range cmdTests { for _, tt := range cmdTests {

View File

@ -1,4 +1,4 @@
Error: shell not specified Error: accepts 1 arg(s), received 0
Usage: Usage:
completion SHELL [flags] completion SHELL [flags]

View File

@ -1,4 +1,4 @@
Error: too many arguments, expected only the shell type Error: accepts 1 arg(s), received 2
Usage: Usage:
completion SHELL [flags] completion SHELL [flags]

View File

@ -18,6 +18,7 @@ package config
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
kubeconfig "k8s.io/client-go/tools/clientcmd/api" kubeconfig "k8s.io/client-go/tools/clientcmd/api"
@ -54,6 +55,18 @@ func TestConfigSetAuthInfo(t *testing.T) {
CmdLine: "--help", CmdLine: "--help",
Cmd: NewCmdConfigSetAuthInfo(nil), Cmd: NewCmdConfigSetAuthInfo(nil),
}, },
{
Name: "config-cmd-set-authinfo-too-many-args",
CmdLine: "arg1 arg2",
Cmd: NewCmdConfigSetAuthInfo(nil),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 2),
},
{
Name: "config-cmd-set-authinfo-too-few-args",
CmdLine: "",
Cmd: NewCmdConfigSetAuthInfo(nil),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
},
} }
for _, tt := range cmdTests { for _, tt := range cmdTests {

View File

@ -18,6 +18,7 @@ package config
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
kubeconfig "k8s.io/client-go/tools/clientcmd/api" kubeconfig "k8s.io/client-go/tools/clientcmd/api"
@ -50,6 +51,18 @@ func TestConfigSetContext(t *testing.T) {
CmdLine: "--help", CmdLine: "--help",
Cmd: NewCmdConfigSetContext(nil), 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 { for _, tt := range cmdTests {

View File

@ -0,0 +1,25 @@
Error: accepts 1 arg(s), received 0
Usage:
set-credentials NAME [flags]
Examples:
# Set only the "client-key" field on the "cluster-admin"
# entry, without touching other values:
airshipctl config set-credentials cluster-admin --username=~/.kube/admin.key
# Set basic auth for the "cluster-admin" entry
airshipctl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
# Embed client certificate data in the "cluster-admin" entry
airshipctl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
Flags:
--client-certificate string Path to client-certificate file for the user entry in airshipctl
--client-key string Path to client-key file for the user entry in airshipctl
--embed-certs Embed client cert/key for the user entry in airshipctl
-h, --help help for set-credentials
--password string password for the user entry in airshipctl
--token string token for the user entry in airshipctl
--username string username for the user entry in airshipctl

View File

@ -0,0 +1,25 @@
Error: accepts 1 arg(s), received 2
Usage:
set-credentials NAME [flags]
Examples:
# Set only the "client-key" field on the "cluster-admin"
# entry, without touching other values:
airshipctl config set-credentials cluster-admin --username=~/.kube/admin.key
# Set basic auth for the "cluster-admin" entry
airshipctl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
# Embed client certificate data in the "cluster-admin" entry
airshipctl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
Flags:
--client-certificate string Path to client-certificate file for the user entry in airshipctl
--client-key string Path to client-key file for the user entry in airshipctl
--embed-certs Embed client cert/key for the user entry in airshipctl
-h, --help help for set-credentials
--password string password for the user entry in airshipctl
--token string token for the user entry in airshipctl
--username string username for the user entry in airshipctl

View File

@ -0,0 +1,21 @@
Error: accepts 1 arg(s), received 0
Usage:
set-context NAME [flags]
Examples:
# Create a completely new e2e context entry
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
# Update the current-context to e2e
airshipctl config set-context e2e --current-context=true
Flags:
--cluster string cluster for the context entry in airshipctl config
--cluster-type string cluster-type for the context entry in airshipctl config
--current-context current-context for the context entry in airshipctl config
-h, --help help for set-context
--manifest string manifest for the context entry in airshipctl config
--namespace string namespace for the context entry in airshipctl config
--user string user for the context entry in airshipctl config

View File

@ -0,0 +1,21 @@
Error: accepts 1 arg(s), received 2
Usage:
set-context NAME [flags]
Examples:
# Create a completely new e2e context entry
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
# Update the current-context to e2e
airshipctl config set-context e2e --current-context=true
Flags:
--cluster string cluster for the context entry in airshipctl config
--cluster-type string cluster-type for the context entry in airshipctl config
--current-context current-context for the context entry in airshipctl config
-h, --help help for set-context
--manifest string manifest for the context entry in airshipctl config
--namespace string namespace for the context entry in airshipctl config
--user string user for the context entry in airshipctl config