(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestInstallCmd_Completion(t *testing.T) { |
| 187 | // Cleanup. |
| 188 | dirs.RemoveAllForTest() |
| 189 | |
| 190 | // Check error. |
| 191 | var check = func(err error) { |
| 192 | t.Helper() |
| 193 | if err != nil { |
| 194 | t.Fatal(err) |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Create mock port structure for testing completion. |
| 199 | testPortDir := dirs.GetPortDir("testlib", "1.0.0") |
| 200 | check(os.MkdirAll(testPortDir, os.ModePerm)) |
| 201 | |
| 202 | // Create a port.toml file |
| 203 | portFile := filepath.Join(testPortDir, "port.toml") |
| 204 | f, err := os.Create(portFile) |
| 205 | check(err) |
| 206 | f.Close() |
| 207 | |
| 208 | celer := configs.NewCeler() |
| 209 | installCmd := installCmd{celer: celer} |
| 210 | cmd := installCmd.Command(celer) |
| 211 | |
| 212 | tests := []struct { |
| 213 | name string |
| 214 | toComplete string |
| 215 | expectContains []string |
| 216 | }{ |
| 217 | { |
| 218 | name: "package completion", |
| 219 | toComplete: "testlib", |
| 220 | expectContains: []string{"testlib@1.0.0"}, |
| 221 | }, |
| 222 | { |
| 223 | name: "flag completion - dev", |
| 224 | toComplete: "--dev", |
| 225 | expectContains: []string{"--dev"}, |
| 226 | }, |
| 227 | { |
| 228 | name: "flag completion - force", |
| 229 | toComplete: "--force", |
| 230 | expectContains: []string{"--force"}, |
| 231 | }, |
| 232 | { |
| 233 | name: "flag completion - short dev", |
| 234 | toComplete: "-d", |
| 235 | expectContains: []string{"-d"}, |
| 236 | }, |
| 237 | { |
| 238 | name: "flag completion - jobs", |
| 239 | toComplete: "--jobs", |
| 240 | expectContains: []string{"--jobs"}, |
| 241 | }, |
| 242 | { |
| 243 | name: "no completion for unknown", |
nothing calls this directly
no test coverage detected