Skip to content

Commit 16a3f43

Browse files
committed
Sort actions in API response to fix flaky test
1 parent 055c73b commit 16a3f43

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/hoverfly_service.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"github.com/SpectoLabs/hoverfly/core/templating"
77
"regexp"
8+
"sort"
89

910
"github.com/SpectoLabs/hoverfly/core/action"
1011
"github.com/SpectoLabs/hoverfly/core/delay"
@@ -465,7 +466,19 @@ func (hf *Hoverfly) GetFilteredDiff(diffFilterView v2.DiffFilterView) map[v2.Sim
465466

466467
func (hf *Hoverfly) GetAllPostServeActions() v2.PostServeActionDetailsView {
467468
var actions []v2.ActionView
468-
for actionName, action := range hf.PostServeActionDetails.Actions {
469+
actionNames := make([]string, 0, len(hf.PostServeActionDetails.Actions))
470+
471+
// Collect all action names
472+
for actionName := range hf.PostServeActionDetails.Actions {
473+
actionNames = append(actionNames, actionName)
474+
}
475+
476+
// Sort action names to enforce natural order
477+
sort.Strings(actionNames)
478+
479+
// Append actions in sorted order
480+
for _, actionName := range actionNames {
481+
action := hf.PostServeActionDetails.Actions[actionName]
469482
actions = append(actions, action.GetActionView(actionName))
470483
}
471484

0 commit comments

Comments
 (0)