From d49e72c0ac99945141a1e3e1d3de35f6637937f5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 2 Oct 2024 10:38:25 +0200 Subject: [PATCH] cli/command/container: add unit tests for completion helpers Signed-off-by: Sebastiaan van Stijn --- cli/command/container/completion_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/command/container/completion_test.go b/cli/command/container/completion_test.go index 25ab31676f..b85aae32d5 100644 --- a/cli/command/container/completion_test.go +++ b/cli/command/container/completion_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/moby/sys/signal" "github.com/spf13/cobra" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -19,3 +20,17 @@ func TestCompleteLinuxCapabilityNames(t *testing.T) { assert.Check(t, is.Equal(name, strings.ToUpper(name)), "Should be formatted uppercase") } } + +func TestCompleteRestartPolicies(t *testing.T) { + values, directives := completeRestartPolicies(nil, nil, "") + assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion") + expected := restartPolicies + assert.Check(t, is.DeepEqual(values, expected)) +} + +func TestCompleteSignals(t *testing.T) { + values, directives := completeSignals(nil, nil, "") + assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion") + assert.Check(t, len(values) > 1) + assert.Check(t, is.Len(values, len(signal.SignalMap))) +}