Skip to content

Commit

Permalink
Order groups and checks chronologically in the end-of-test summary
Browse files Browse the repository at this point in the history
This closes grafana#1316
  • Loading branch information
na-- authored and salem84 committed Feb 3, 2021
1 parent 6ba4879 commit fd2577d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 7 additions & 2 deletions lib/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ type Group struct {
ID string `json:"id"`

// Groups and checks that are children of this group.
Groups map[string]*Group `json:"groups"`
Checks map[string]*Check `json:"checks"`
Groups map[string]*Group `json:"groups"`
OrderedGroups []*Group `json:"-"`

Checks map[string]*Check `json:"checks"`
OrderedChecks []*Check `json:"-"`

groupMutex sync.Mutex
checkMutex sync.Mutex
Expand Down Expand Up @@ -155,6 +158,7 @@ func (g *Group) Group(name string) (*Group, error) {
return nil, err
}
g.Groups[name] = group
g.OrderedGroups = append(g.OrderedGroups, group)
return group, nil
}
return group, nil
Expand All @@ -172,6 +176,7 @@ func (g *Group) Check(name string) (*Check, error) {
return nil, err
}
g.Checks[name] = check
g.OrderedChecks = append(g.OrderedChecks, check)
return check, nil
}
return check, nil
Expand Down
4 changes: 2 additions & 2 deletions ui/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func summarizeGroup(w io.Writer, indent string, group *lib.Group) {
}

var checkNames []string
for _, check := range group.Checks {
for _, check := range group.OrderedChecks {
checkNames = append(checkNames, check.Name)
}
for _, name := range checkNames {
Expand All @@ -206,7 +206,7 @@ func summarizeGroup(w io.Writer, indent string, group *lib.Group) {
}

var groupNames []string
for _, grp := range group.Groups {
for _, grp := range group.OrderedGroups {
groupNames = append(groupNames, grp.Name)
}
for _, name := range groupNames {
Expand Down
14 changes: 9 additions & 5 deletions ui/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import (
func TestSummary(t *testing.T) {
t.Run("SummarizeMetrics", func(t *testing.T) {
var (
checksOut = " █ child\n\n ✗ check1\n ↳ 33% — ✓ 5 / ✗ 10\n\n" +
checksOut = " █ child\n\n" +
" ✗ check1\n ↳ 33% — ✓ 5 / ✗ 10\n" +
" ✗ check2\n ↳ 66% — ✓ 10 / ✗ 5\n\n" +
" ✓ checks......: 100.00% ✓ 3 ✗ 0 \n"
countOut = " ✗ http_reqs...: 3 3/s\n"
gaugeOut = " vus.........: 1 min=1 max=1\n"
Expand All @@ -58,10 +60,12 @@ func TestSummary(t *testing.T) {

rootG, _ := lib.NewGroup("", nil)
childG, _ := rootG.Group("child")
check, _ := lib.NewCheck("check1", childG)
check.Passes = 5
check.Fails = 10
childG.Checks["check1"] = check
check1, _ := childG.Check("check1")
check1.Passes = 5
check1.Fails = 10
check2, _ := childG.Check("check2")
check2.Passes = 10
check2.Fails = 5
for _, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("%v", tc.stats), func(t *testing.T) {
Expand Down

0 comments on commit fd2577d

Please sign in to comment.