(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestInstallCmd_CommandStructure(t *testing.T) { |
| 19 | // Cleanup. |
| 20 | dirs.RemoveAllForTest() |
| 21 | |
| 22 | celer := configs.NewCeler() |
| 23 | installCmd := installCmd{} |
| 24 | cmd := installCmd.Command(celer) |
| 25 | |
| 26 | t.Run("command_structure", func(t *testing.T) { |
| 27 | if cmd.Use != "install" { |
| 28 | t.Errorf("Expected Use to be 'install', got '%s'", cmd.Use) |
| 29 | } |
| 30 | |
| 31 | if cmd.Short == "" { |
| 32 | t.Error("Short description should not be empty") |
| 33 | } |
| 34 | |
| 35 | if cmd.Long == "" { |
| 36 | t.Error("Long description should not be empty") |
| 37 | } |
| 38 | |
| 39 | // Check that argument validation exists. |
| 40 | if cmd.Args == nil { |
| 41 | t.Error("Args should be set") |
| 42 | } |
| 43 | |
| 44 | if err := cmd.Args(cmd, []string{}); err == nil { |
| 45 | t.Error("Args should require at least one package") |
| 46 | } |
| 47 | |
| 48 | if err := cmd.Args(cmd, []string{"opencv@4.8.0"}); err != nil { |
| 49 | t.Errorf("single package should be accepted, got: %v", err) |
| 50 | } |
| 51 | |
| 52 | if err := cmd.Args(cmd, []string{"opencv@4.8.0", "eigen@3.4.0"}); err != nil { |
| 53 | t.Errorf("multiple packages should be accepted, got: %v", err) |
| 54 | } |
| 55 | }) |
| 56 | |
| 57 | t.Run("flags_configuration", func(t *testing.T) { |
| 58 | flags := []struct { |
| 59 | name string |
| 60 | shorthand string |
| 61 | }{ |
| 62 | {"dev", "d"}, |
| 63 | {"force", "f"}, |
| 64 | {"recursive", "r"}, |
| 65 | {"jobs", "j"}, |
| 66 | {"verbose", "v"}, |
| 67 | } |
| 68 | |
| 69 | for _, flag := range flags { |
| 70 | f := cmd.Flags().Lookup(flag.name) |
| 71 | if f == nil { |
| 72 | t.Errorf("--%s flag should be defined", flag.name) |
| 73 | } else if f.Shorthand != flag.shorthand { |
| 74 | t.Errorf("Expected %s flag shorthand to be '%s', got '%s'", flag.name, flag.shorthand, f.Shorthand) |
| 75 | } |
nothing calls this directly
no test coverage detected