Skip to content

Commit

Permalink
Revert "WIP unit-test dynamic completion"
Browse files Browse the repository at this point in the history
Like in kubectl own completion tests, we now have an independent
'completion' package with its own tests. Stop testing in cmd/ callers
packages.

This reverts commit 75eb5ae.

Signed-off-by: Thomas Riccardi <[email protected]>
  • Loading branch information
thomas-riccardi committed Oct 31, 2022
1 parent d60c37c commit 17851c8
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions pkg/kubectl-argo-rollouts/cmd/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package get
import (
"bytes"
"fmt"
"sort"
"strings"
"testing"
"time"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"k8s.io/cli-runtime/pkg/genericclioptions"

Expand Down Expand Up @@ -563,48 +561,3 @@ NAME KIND STATUS
`, "\n")
assertStdout(t, expectedOut, o.IOStreams)
}

func TestCompletionGetRollout(t *testing.T) {
rolloutObjs := testdata.NewCanaryRollout()

tf, o := options.NewFakeArgoRolloutsOptions(rolloutObjs.AllObjects()...)
o.RESTClientGetter = tf.WithNamespace(rolloutObjs.Rollouts[0].Namespace)
defer tf.Cleanup()
cmd := NewCmdGetRollout(o)
cmd.PersistentPreRunE = o.PersistentPreRunE

comps, directive := cmd.ValidArgsFunction(cmd, []string{}, "")
checkCompletion(t, comps, []string{"canary-demo", "canary-demo-pingpong", "canary-demo-weights", "canary-demo-weights-na", "canary-demo-workloadRef", "canary-demo-workloadRef-deploy"}, directive, cobra.ShellCompDirectiveNoFileComp)

comps, directive = cmd.ValidArgsFunction(cmd, []string{}, "cana")
checkCompletion(t, comps, []string{"canary-demo", "canary-demo-pingpong", "canary-demo-weights", "canary-demo-weights-na", "canary-demo-workloadRef", "canary-demo-workloadRef-deploy"}, directive, cobra.ShellCompDirectiveNoFileComp)

comps, directive = cmd.ValidArgsFunction(cmd, []string{}, "canary-demo")
checkCompletion(t, comps, []string{"canary-demo", "canary-demo-pingpong", "canary-demo-weights", "canary-demo-weights-na", "canary-demo-workloadRef", "canary-demo-workloadRef-deploy"}, directive, cobra.ShellCompDirectiveNoFileComp)

comps, directive = cmd.ValidArgsFunction(cmd, []string{}, "canary-demo-p")
checkCompletion(t, comps, []string{"canary-demo-pingpong"}, directive, cobra.ShellCompDirectiveNoFileComp)

comps, directive = cmd.ValidArgsFunction(cmd, []string{}, "seagull")
checkCompletion(t, comps, []string{}, directive, cobra.ShellCompDirectiveNoFileComp)
}

func checkCompletion(t *testing.T, comps, expectedComps []string, directive, expectedDirective cobra.ShellCompDirective) {
if e, d := expectedDirective, directive; e != d {
t.Errorf("expected directive\n%v\nbut got\n%v", e, d)
}

sort.Strings(comps)
sort.Strings(expectedComps)

if len(expectedComps) != len(comps) {
t.Fatalf("expected completions\n%v\nbut got\n%v", expectedComps, comps)
}

for i := range comps {
if expectedComps[i] != comps[i] {
t.Errorf("expected completions\n%v\nbut got\n%v", expectedComps, comps)
break
}
}
}

0 comments on commit 17851c8

Please sign in to comment.