Skip to content

Commit

Permalink
test: Add test for invalid shell completion value
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Aug 28, 2023
1 parent 7067afc commit 8032a25
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,25 @@ func TestSBCEnvs(t *testing.T) {
}

func TestCompletionFlag(t *testing.T) {
for _, shell := range []string{"bash", "zsh", "fish", "powershell"} {
t.Run(shell, func(t *testing.T) {
tests := []struct {
shell string
errAssertion assert.ErrorAssertionFunc
}{
{"bash", assert.NoError},
{"zsh", assert.NoError},
{"fish", assert.NoError},
{"powershell", assert.NoError},
{"invalid", assert.Error},
}
for _, tt := range tests {
t.Run(tt.shell, func(t *testing.T) {
cmd := NewCommand("", "")
cmd.SetArgs([]string{"--completion", shell})
cmd.SetArgs([]string{"--completion", tt.shell})

var buf bytes.Buffer
cmd.SetOut(&buf)

if err := cmd.Execute(); !assert.NoError(t, err) {
if err := cmd.Execute(); !tt.errAssertion(t, err) {
return
}

Expand Down

0 comments on commit 8032a25

Please sign in to comment.