From 478e54b47dd332bcb559542077e4175a96b876ed Mon Sep 17 00:00:00 2001 From: Trevin Teacutter Date: Thu, 1 Mar 2018 16:18:23 -0600 Subject: [PATCH 1/2] Prevent null values from being reported in json --- lib/metrics.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/metrics.go b/lib/metrics.go index 350b103d..fba00f7b 100644 --- a/lib/metrics.go +++ b/lib/metrics.go @@ -144,4 +144,8 @@ func (m *Metrics) init() { quantile.Known(0.99, 0.0005), ) } + + if m.Errors == nil { + m.Errors = make([]string, 0) + } } From 5cff1c05df8bbee575d32e525e104bf22d3c6243 Mon Sep 17 00:00:00 2001 From: Trevin Teacutter Date: Mon, 14 May 2018 16:30:29 -0500 Subject: [PATCH 2/2] Added test for nil Metrics.Errors slice --- lib/metrics_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/metrics_test.go b/lib/metrics_test.go index 75f5b861..9ba2bc34 100644 --- a/lib/metrics_test.go +++ b/lib/metrics_test.go @@ -76,3 +76,17 @@ func TestMetrics_NoInfiniteRate(t *testing.T) { t.Errorf("got rate %f, want %f", got, want) } } + +// https://github.com/tsenart/vegeta/pull/277 +func TestMetrics_NilErrorOnClose(t *testing.T) { + t.Parallel() + + m := Metrics{Errors: nil} + m.Close() + + got, want := m.Errors, []string{} + + if !reflect.DeepEqual(got, want) { + t.Errorf("\ngot: %+v\nwant: %+v", got, want) + } +}