File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "testing"
5+
6+ "github.com/spf13/cobra"
7+ )
8+
9+ func findCommandByName (parent * cobra.Command , use string ) * cobra.Command {
10+ for _ , c := range parent .Commands () {
11+ if c .Name () == use {
12+ return c
13+ }
14+ }
15+ return nil
16+ }
17+
18+ func TestVersionCommandIsRegistered (t * testing.T ) {
19+ if got := findCommandByName (rootCmd , "version" ); got == nil {
20+ t .Fatalf ("expected version command to be registered on root" )
21+ }
22+ }
23+
24+ func TestRootVersionMatchesConstant (t * testing.T ) {
25+ if rootCmd .Version != CLI_VERSION {
26+ t .Fatalf ("expected root version %q to match CLI version %q" , rootCmd .Version , CLI_VERSION )
27+ }
28+ }
29+
30+ func TestK8sInitCommandIsRegistered (t * testing.T ) {
31+ k8s := findCommandByName (rootCmd , "k8s" )
32+ if k8s == nil {
33+ t .Fatalf ("expected k8s command to be registered on root" )
34+ }
35+
36+ if got := findCommandByName (k8s , "init" ); got == nil {
37+ t .Fatalf ("expected k8s init subcommand to be registered" )
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments