(t *testing.T)
| 354 | } |
| 355 | |
| 356 | func TestInstallCmd_ErrorHandling(t *testing.T) { |
| 357 | // Cleanup. |
| 358 | dirs.RemoveAllForTest() |
| 359 | |
| 360 | tests := []struct { |
| 361 | name string |
| 362 | input string |
| 363 | expectError string |
| 364 | }{ |
| 365 | { |
| 366 | name: "empty package name", |
| 367 | input: "", |
| 368 | expectError: "package name cannot be empty", |
| 369 | }, |
| 370 | { |
| 371 | name: "invalid format - no version", |
| 372 | input: "opencv", |
| 373 | expectError: "package must be specified in name@version format", |
| 374 | }, |
| 375 | { |
| 376 | name: "invalid format - empty name", |
| 377 | input: "@4.8.0", |
| 378 | expectError: "package name cannot be empty", |
| 379 | }, |
| 380 | { |
| 381 | name: "invalid format - empty version", |
| 382 | input: "opencv@", |
| 383 | expectError: "package version cannot be empty", |
| 384 | }, |
| 385 | } |
| 386 | |
| 387 | installCmd := &installCmd{} |
| 388 | for _, test := range tests { |
| 389 | t.Run(test.name, func(t *testing.T) { |
| 390 | _, err := installCmd.validateAndCleanInput(test.input) |
| 391 | if err == nil { |
| 392 | t.Errorf("Expected error for input '%s' but got none", test.input) |
| 393 | return |
| 394 | } |
| 395 | |
| 396 | if !strings.Contains(err.Error(), test.expectError) { |
| 397 | t.Errorf("Expected error containing '%s' for input '%s', got: %v", test.expectError, test.input, err) |
| 398 | } |
| 399 | }) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | func TestInstallCmd_RunInstall_MultiPackages_PreInitValidation(t *testing.T) { |
| 404 | installCmd := &installCmd{} |
nothing calls this directly
no test coverage detected