|
| 1 | +package cli |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + cmdpkg "github.com/lets-cli/lets/internal/cmd" |
| 7 | + "github.com/spf13/cobra" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAllowsMissingConfig(t *testing.T) { |
| 11 | + t.Run("help", func(t *testing.T) { |
| 12 | + command := &cobra.Command{Use: "help"} |
| 13 | + if !allowsMissingConfig(command) { |
| 14 | + t.Fatal("expected help to allow missing config") |
| 15 | + } |
| 16 | + }) |
| 17 | + |
| 18 | + t.Run("completion", func(t *testing.T) { |
| 19 | + root := cmdpkg.CreateRootCommand("v0.0.0-test", "") |
| 20 | + cmdpkg.InitCompletionCmd(root, nil) |
| 21 | + |
| 22 | + command, _, err := root.Find([]string{"completion"}) |
| 23 | + if err != nil { |
| 24 | + t.Fatalf("unexpected error: %v", err) |
| 25 | + } |
| 26 | + |
| 27 | + if !allowsMissingConfig(command) { |
| 28 | + t.Fatal("expected completion to allow missing config") |
| 29 | + } |
| 30 | + }) |
| 31 | + |
| 32 | + t.Run("self subcommand", func(t *testing.T) { |
| 33 | + root := cmdpkg.CreateRootCommand("v0.0.0-test", "") |
| 34 | + cmdpkg.InitSelfCmd(root, "v0.0.0-test") |
| 35 | + |
| 36 | + command, _, err := root.Find([]string{"self", "doc"}) |
| 37 | + if err != nil { |
| 38 | + t.Fatalf("unexpected error: %v", err) |
| 39 | + } |
| 40 | + |
| 41 | + if !allowsMissingConfig(command) { |
| 42 | + t.Fatal("expected lets self doc to allow missing config") |
| 43 | + } |
| 44 | + }) |
| 45 | + |
| 46 | + t.Run("top level doc does not match self", func(t *testing.T) { |
| 47 | + root := cmdpkg.CreateRootCommand("v0.0.0-test", "") |
| 48 | + root.AddCommand(&cobra.Command{Use: "doc"}) |
| 49 | + |
| 50 | + command, _, err := root.Find([]string{"doc"}) |
| 51 | + if err != nil { |
| 52 | + t.Fatalf("unexpected error: %v", err) |
| 53 | + } |
| 54 | + |
| 55 | + if allowsMissingConfig(command) { |
| 56 | + t.Fatal("expected top-level doc to require config") |
| 57 | + } |
| 58 | + }) |
| 59 | +} |
0 commit comments