metrics: fix issues reported by staticcheck (#20365)

This commit is contained in:
Guillaume Ballet
2019-11-22 16:04:35 +01:00
committed by Felix Lange
parent dd21f079e8
commit 58f2ce8671
15 changed files with 109 additions and 105 deletions

View File

@ -14,7 +14,7 @@ func TestGetOrRegisterHistogram(t *testing.T) {
r := NewRegistry()
s := NewUniformSample(100)
NewRegisteredHistogram("foo", r, s).Update(47)
if h := GetOrRegisterHistogram("foo", r, s); 1 != h.Count() {
if h := GetOrRegisterHistogram("foo", r, s); h.Count() != 1 {
t.Fatal(h)
}
}
@ -29,29 +29,29 @@ func TestHistogram10000(t *testing.T) {
func TestHistogramEmpty(t *testing.T) {
h := NewHistogram(NewUniformSample(100))
if count := h.Count(); 0 != count {
if count := h.Count(); count != 0 {
t.Errorf("h.Count(): 0 != %v\n", count)
}
if min := h.Min(); 0 != min {
if min := h.Min(); min != 0 {
t.Errorf("h.Min(): 0 != %v\n", min)
}
if max := h.Max(); 0 != max {
if max := h.Max(); max != 0 {
t.Errorf("h.Max(): 0 != %v\n", max)
}
if mean := h.Mean(); 0.0 != mean {
if mean := h.Mean(); mean != 0.0 {
t.Errorf("h.Mean(): 0.0 != %v\n", mean)
}
if stdDev := h.StdDev(); 0.0 != stdDev {
if stdDev := h.StdDev(); stdDev != 0.0 {
t.Errorf("h.StdDev(): 0.0 != %v\n", stdDev)
}
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
if 0.0 != ps[0] {
if ps[0] != 0.0 {
t.Errorf("median: 0.0 != %v\n", ps[0])
}
if 0.0 != ps[1] {
if ps[1] != 0.0 {
t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
}
if 0.0 != ps[2] {
if ps[2] != 0.0 {
t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
}
}
@ -67,29 +67,29 @@ func TestHistogramSnapshot(t *testing.T) {
}
func testHistogram10000(t *testing.T, h Histogram) {
if count := h.Count(); 10000 != count {
if count := h.Count(); count != 10000 {
t.Errorf("h.Count(): 10000 != %v\n", count)
}
if min := h.Min(); 1 != min {
if min := h.Min(); min != 1 {
t.Errorf("h.Min(): 1 != %v\n", min)
}
if max := h.Max(); 10000 != max {
if max := h.Max(); max != 10000 {
t.Errorf("h.Max(): 10000 != %v\n", max)
}
if mean := h.Mean(); 5000.5 != mean {
if mean := h.Mean(); mean != 5000.5 {
t.Errorf("h.Mean(): 5000.5 != %v\n", mean)
}
if stdDev := h.StdDev(); 2886.751331514372 != stdDev {
if stdDev := h.StdDev(); stdDev != 2886.751331514372 {
t.Errorf("h.StdDev(): 2886.751331514372 != %v\n", stdDev)
}
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
if 5000.5 != ps[0] {
if ps[0] != 5000.5 {
t.Errorf("median: 5000.5 != %v\n", ps[0])
}
if 7500.75 != ps[1] {
if ps[1] != 7500.75 {
t.Errorf("75th percentile: 7500.75 != %v\n", ps[1])
}
if 9900.99 != ps[2] {
if ps[2] != 9900.99 {
t.Errorf("99th percentile: 9900.99 != %v\n", ps[2])
}
}