Skip to content

Commit

Permalink
Merge pull request tsenart#277 from TrevinTeacutter/master
Browse files Browse the repository at this point in the history
Prevent null values from being reported in json
  • Loading branch information
tsenart authored May 18, 2018
2 parents 2da25b2 + 5cff1c0 commit 9b3f61d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,8 @@ func (m *Metrics) init() {
quantile.Known(0.99, 0.0005),
)
}

if m.Errors == nil {
m.Errors = make([]string, 0)
}
}
14 changes: 14 additions & 0 deletions lib/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 9b3f61d

Please sign in to comment.