Package list golang-github-go-kit-kit / 9e2127e
Issue #529: Extracted FillCounter() from TestCounter() to reuse counter-filling logic in cloudwatch_test.go Alejandro Pedraza 4 years ago
1 changed file(s) with 11 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1313 // TestCounter puts some deltas through the counter, and then calls the value
1414 // func to check that the counter has the correct final value.
1515 func TestCounter(counter metrics.Counter, value func() float64) error {
16 want := FillCounter(counter)
17 if have := value(); want != have {
18 return fmt.Errorf("want %f, have %f", want, have)
19 }
20
21 return nil
22 }
23
24 // FillCounter puts some deltas through the counter and returns the total value.
25 func FillCounter(counter metrics.Counter) float64 {
1626 a := rand.Perm(100)
1727 n := rand.Intn(len(a))
1828
2232 counter.Add(f)
2333 want += f
2434 }
25
26 if have := value(); want != have {
27 return fmt.Errorf("want %f, have %f", want, have)
28 }
29
30 return nil
35 return want
3136 }
3237
3338 // TestGauge puts some values through the gauge, and then calls the value func