From 8032a257b503ee038990c1f515857942500aa8b4 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 28 Aug 2023 14:07:55 -0500 Subject: [PATCH] test: Add test for invalid shell completion value --- cmd/cmd_test.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 84ed55e..33122b5 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -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 }