Skip to content

Commit

Permalink
Present problem types in a consistent order.
Browse files Browse the repository at this point in the history
Go ranges over map keys in a random order by design.  The `FakeUI` test
framework requires you to give answers to ui prompts in a specific
order, and does not allow you to react to the prompts with a given
input.

[#185483613]

Authored-by: Chris Selzo <cselzo@vmware.com>
  • Loading branch information
selzoc committed Jul 5, 2023
1 parent 85dafdd commit dd7ff53
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/create_recovery_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c CreateRecoveryPlanCmd) Run(opts CreateRecoveryPlanOpts) error {
}

var plan RecoveryPlan
for _, instanceGroup := range sortedInstanceGroups(problemsByInstanceGroup) {
for _, instanceGroup := range sortedMapKeys(problemsByInstanceGroup) {
c.ui.PrintLinef("Instance Group '%s'\n", instanceGroup)

instanceGroupResolutions, err := c.processProblemsByType(problemsByInstanceGroup[instanceGroup])
Expand Down Expand Up @@ -125,21 +125,22 @@ func (c CreateRecoveryPlanCmd) getMaxInFlightByInstanceGroup() (map[string]strin
return flightMap, nil
}

func sortedInstanceGroups(problemsByInstanceGroup map[string][]boshdir.Problem) []string {
var instanceGroups []string
for k := range problemsByInstanceGroup {
instanceGroups = append(instanceGroups, k)
func sortedMapKeys(problemMap map[string][]boshdir.Problem) []string {
var keys []string
for k := range problemMap {
keys = append(keys, k)
}
sort.Strings(instanceGroups)
sort.Strings(keys)

return instanceGroups
return keys
}

func (c CreateRecoveryPlanCmd) processProblemsByType(problems []boshdir.Problem) (map[string]string, error) {
problemsByType := mapProblemsByTrait(problems, func(p boshdir.Problem) string { return p.Type })

resolutions := make(map[string]string)
for problemType, problemsForType := range problemsByType {
for _, problemType := range sortedMapKeys(problemsByType) {
problemsForType := problemsByType[problemType]
c.printProblemTable(problemType, problemsForType)

var opts []string
Expand Down

0 comments on commit dd7ff53

Please sign in to comment.