Skip to content

Commit 8f2e566

Browse files
committed
completion: add test for EnvVarNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent b8cddc6 commit 8f2e566

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

cli/command/completion/functions_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
package completion
22

33
import (
4+
"sort"
45
"testing"
56

67
"github.com/spf13/cobra"
78
"gotest.tools/v3/assert"
89
is "gotest.tools/v3/assert/cmp"
10+
"gotest.tools/v3/env"
911
)
1012

13+
func TestCompleteEnvVarNames(t *testing.T) {
14+
env.PatchAll(t, map[string]string{
15+
"ENV_A": "hello-a",
16+
"ENV_B": "hello-b",
17+
})
18+
values, directives := EnvVarNames(nil, nil, "")
19+
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")
20+
21+
sort.Strings(values)
22+
expected := []string{"ENV_A", "ENV_B"}
23+
assert.Check(t, is.DeepEqual(values, expected))
24+
}
25+
1126
func TestCompletePlatforms(t *testing.T) {
1227
values, directives := Platforms(nil, nil, "")
1328
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")

0 commit comments

Comments
 (0)