
In the completion command validation was being done at runtime to determine if too many or too few args were being passed in. This approach required extra unit tests to validate the behavior. This patch seeks to streamline the code by specifying the number of args expected when initializing the cobra command, and allowing cobra to throw an error before doing any work in go if the number of args is incorrect. As a result the unit tests for too many and too few args are no longer needed for this package and have been removed. Change-Id: If0cf043713ef08333f17b010210352205d74c4ee
37 lines
627 B
Go
37 lines
627 B
Go
package completion_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"opendev.org/airship/airshipctl/cmd/completion"
|
|
"opendev.org/airship/airshipctl/testutil"
|
|
)
|
|
|
|
func TestCompletion(t *testing.T) {
|
|
cmd := completion.NewCompletionCommand()
|
|
|
|
cmdTests := []*testutil.CmdTest{
|
|
{
|
|
Name: "completion-bash",
|
|
CmdLine: "bash",
|
|
Cmd: cmd,
|
|
},
|
|
{
|
|
Name: "completion-zsh",
|
|
CmdLine: "zsh",
|
|
Cmd: cmd,
|
|
},
|
|
{
|
|
Name: "completion-unknown-shell",
|
|
CmdLine: "fish",
|
|
Cmd: cmd,
|
|
Error: errors.New("unsupported shell type \"fish\""),
|
|
},
|
|
}
|
|
|
|
for _, tt := range cmdTests {
|
|
testutil.RunTest(t, tt)
|
|
}
|
|
}
|