(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func TestRoot(t *testing.T) { |
| 105 | t.Parallel() |
| 106 | t.Run("MissingRootCommand", func(t *testing.T) { |
| 107 | t.Parallel() |
| 108 | |
| 109 | out := new(bytes.Buffer) |
| 110 | |
| 111 | inv, _ := clitest.New(t, "idontexist") |
| 112 | inv.Stdout = out |
| 113 | |
| 114 | err := inv.Run() |
| 115 | assert.ErrorContains(t, err, |
| 116 | `unrecognized subcommand "idontexist"`) |
| 117 | require.Empty(t, out.String()) |
| 118 | }) |
| 119 | |
| 120 | t.Run("MissingSubcommand", func(t *testing.T) { |
| 121 | t.Parallel() |
| 122 | |
| 123 | out := new(bytes.Buffer) |
| 124 | |
| 125 | inv, _ := clitest.New(t, "server", "idontexist") |
| 126 | inv.Stdout = out |
| 127 | |
| 128 | err := inv.Run() |
| 129 | // subcommand error only when command has subcommands |
| 130 | assert.ErrorContains(t, err, |
| 131 | `unrecognized subcommand "idontexist"`) |
| 132 | require.Empty(t, out.String()) |
| 133 | }) |
| 134 | |
| 135 | t.Run("BadSubcommandArgs", func(t *testing.T) { |
| 136 | t.Parallel() |
| 137 | |
| 138 | out := new(bytes.Buffer) |
| 139 | |
| 140 | inv, _ := clitest.New(t, "list", "idontexist") |
| 141 | inv.Stdout = out |
| 142 | |
| 143 | err := inv.Run() |
| 144 | assert.ErrorContains(t, err, |
| 145 | `wanted no args but got 1 [idontexist]`) |
| 146 | require.Empty(t, out.String()) |
| 147 | }) |
| 148 | |
| 149 | t.Run("Version", func(t *testing.T) { |
| 150 | t.Parallel() |
| 151 | |
| 152 | buf := new(bytes.Buffer) |
| 153 | inv, _ := clitest.New(t, "version") |
| 154 | inv.Stdout = buf |
| 155 | err := inv.Run() |
| 156 | require.NoError(t, err) |
| 157 | |
| 158 | output := buf.String() |
| 159 | require.Contains(t, output, buildinfo.Version(), "has version") |
| 160 | require.Contains(t, output, buildinfo.ExternalURL(), "has url") |
| 161 | }) |
nothing calls this directly
no test coverage detected