From 371d0fada48d3f648a714f2c0e1761d4e9f47572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Wed, 16 Oct 2019 16:40:38 +0200 Subject: [PATCH] test(ui): add group to SummarizeMetrics test to increase coverage Resolves: https://github.com/loadimpact/k6/pull/1143#discussion_r335438820 --- ui/summary_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/summary_test.go b/ui/summary_test.go index 87f505d66ba..bdc26cf1b13 100644 --- a/ui/summary_test.go +++ b/ui/summary_test.go @@ -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" @@ -34,10 +35,12 @@ 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() @@ -45,11 +48,18 @@ func TestSummary(t *testing.T) { 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) { @@ -58,7 +68,7 @@ func TestSummary(t *testing.T) { s.SummarizeMetrics(&w, " ", SummaryData{ Metrics: metrics, - RootGroup: nil, + RootGroup: rootG, Time: time.Second, TimeUnit: "", })