Skip to content

Commit 1ad9c88

Browse files
test: add minimal wiring tests for version and k8s init command registration
1 parent fc5a92e commit 1ad9c88

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

cmd/wiring_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)