|
| 1 | +package cli |
| 2 | + |
| 3 | +import ( |
| 4 | + "sort" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +var expectedCommands = []string{"login", "switch [organization]", "verification", "run", "version"} |
| 11 | + |
| 12 | +func TestMainCommand(t *testing.T) { |
| 13 | + t.Run("Main command", func(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + cmd := createMainCommand() |
| 17 | + assert.NotNil(t, cmd, "Expected main command to be created") |
| 18 | + |
| 19 | + groups := cmd.Groups() |
| 20 | + assert.Len(t, groups, 2, "Expected 2 groups") |
| 21 | + assert.Equal(t, "management", groups[0].ID, "Expected first group to be 'management'") |
| 22 | + assert.Equal(t, "dispatch", groups[1].ID, "Expected second group to be 'dispatch'") |
| 23 | + |
| 24 | + commands := cmd.Commands() |
| 25 | + assert.Len(t, commands, 5, "Expected 5 commands") |
| 26 | + |
| 27 | + // Extract the command IDs |
| 28 | + commandIDs := make([]string, 0, len(commands)) |
| 29 | + for _, command := range commands { |
| 30 | + commandIDs = append(commandIDs, command.Use) |
| 31 | + } |
| 32 | + |
| 33 | + // Sort slices alphabetically |
| 34 | + sort.Strings(expectedCommands) |
| 35 | + assert.Equal(t, expectedCommands, commandIDs, "All commands should be present in the main command") |
| 36 | + }) |
| 37 | +} |
0 commit comments