cli/command/completion_test.go
Mislav Marohnić 2abee0905b Add fish completion support via Cobra contributor
Co-authored-by: Tim Reddehase <tim.reddehase@xing.com>
2020-01-28 22:04:40 +01:00

46 lines
1 KiB
Go

package command
import (
"strings"
"testing"
)
func TestCompletion_bash(t *testing.T) {
output, err := RunCommand(completionCmd, `completion`)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output.String(), "complete -o default -F __start_gh gh") {
t.Errorf("problem in bash completion:\n%s", output)
}
}
func TestCompletion_zsh(t *testing.T) {
output, err := RunCommand(completionCmd, `completion -s zsh`)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output.String(), "#compdef _gh gh") {
t.Errorf("problem in zsh completion:\n%s", output)
}
}
func TestCompletion_fish(t *testing.T) {
output, err := RunCommand(completionCmd, `completion -s fish`)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output.String(), "complete -c gh ") {
t.Errorf("problem in fish completion:\n%s", output)
}
}
func TestCompletion_unsupported(t *testing.T) {
_, err := RunCommand(completionCmd, `completion -s csh`)
if err == nil || err.Error() != `unsupported shell type "csh"` {
t.Fatal(err)
}
}