Skip to content

Commit

Permalink
test(ui): add group to SummarizeMetrics test to increase coverage
Browse files Browse the repository at this point in the history
Resolves: #1143 (comment)
  • Loading branch information
Ivan Mirić committed Oct 16, 2019
1 parent 4b572a8 commit 371d0fa
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ui/summary_test.go
Expand Up @@ -26,6 +26,7 @@ import (
"testing"
"time"

"github.com/loadimpact/k6/lib"
"github.com/loadimpact/k6/stats"
"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v3"
Expand All @@ -34,22 +35,31 @@ import (
func TestSummary(t *testing.T) {
t.Run("SummarizeMetrics", func(t *testing.T) {
var (
checksOut = " ✓ checks......: 100.00% ✓ 3 ✗ 0 \n"
countOut = " ✗ http_reqs...: 3 3/s\n"
gaugeOut = " vus.........: 1 min=1 max=1\n"
trendOut = " my_trend....: avg=15ms min=10ms med=15ms max=20ms p(90)=19ms p(95)=19.5ms\n"
checksOut = " █ child\n\n ✗ check1\n ↳ 33% — ✓ 5 / ✗ 10\n\n" +
" ✓ checks......: 100.00% ✓ 3 ✗ 0 \n"
countOut = " ✗ http_reqs...: 3 3/s\n"
gaugeOut = " vus.........: 1 min=1 max=1\n"
trendOut = " my_trend....: avg=15ms min=10ms med=15ms max=20ms p(90)=19ms " +
"p(95)=19.5ms p(99.9)=19.99ms\n"
)

metrics := createTestMetrics()
testCases := []struct {
stats []string
expected string
}{
{[]string{"avg", "min", "med", "max", "p(90)", "p(95)"}, checksOut + countOut + trendOut + gaugeOut},
{[]string{"avg", "min", "med", "max", "p(90)", "p(95)", "p(99.9)"},
checksOut + countOut + trendOut + gaugeOut},
{[]string{"count"}, checksOut + countOut + " my_trend....: count=3\n" + gaugeOut},
{[]string{"avg", "count"}, checksOut + countOut + " my_trend....: avg=15ms count=3\n" + gaugeOut},
}

rootG, _ := lib.NewGroup("", nil)
childG, _ := rootG.Group("child")
check, _ := lib.NewCheck("check1", childG)
check.Passes = 5
check.Fails = 10
childG.Checks["check1"] = check
for _, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("%v", tc.stats), func(t *testing.T) {
Expand All @@ -58,7 +68,7 @@ func TestSummary(t *testing.T) {

s.SummarizeMetrics(&w, " ", SummaryData{
Metrics: metrics,
RootGroup: nil,
RootGroup: rootG,
Time: time.Second,
TimeUnit: "",
})
Expand Down

0 comments on commit 371d0fa

Please sign in to comment.