-
-
Save imiric/f2a043c778df1a2e69ebbdfac2149af0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestSummarize(t *testing.T) { | |
var ( | |
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)", "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 | |
options := lib.Options{SummaryTimeUnit: null.StringFrom("")} | |
for _, tc := range testCases { | |
tc := tc | |
t.Run(fmt.Sprintf("%v", tc.stats), func(t *testing.T) { | |
var w bytes.Buffer | |
TrendColumns = defaultTrendColumns | |
UpdateTrendColumns(tc.stats) | |
Summarize(&w, " ", SummaryData{ | |
Metrics: metrics, | |
Root: rootG, | |
Time: time.Second, | |
Opts: options, | |
}) | |
assert.Equal(t, tc.expected, w.String()) | |
}) | |
} | |
} | |
func createTestMetrics() map[string]*stats.Metric { | |
metrics := make(map[string]*stats.Metric) | |
gaugeMetric := stats.New("vus", stats.Gauge) | |
gaugeMetric.Sink.Add(stats.Sample{Value: 1}) | |
countMetric := stats.New("http_reqs", stats.Counter) | |
countMetric.Tainted = null.BoolFrom(true) | |
checksMetric := stats.New("checks", stats.Rate) | |
checksMetric.Tainted = null.BoolFrom(false) | |
sink := &stats.TrendSink{} | |
samples := []float64{10.0, 15.0, 20.0} | |
for _, s := range samples { | |
sink.Add(stats.Sample{Value: s}) | |
checksMetric.Sink.Add(stats.Sample{Value: 1}) | |
countMetric.Sink.Add(stats.Sample{Value: 1}) | |
} | |
metrics["vus"] = gaugeMetric | |
metrics["http_reqs"] = countMetric | |
metrics["checks"] = checksMetric | |
metrics["my_trend"] = &stats.Metric{Name: "my_trend", Type: stats.Trend, Contains: stats.Time, Sink: sink} | |
return metrics | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment