Issue #529: Extracted FillCounter() from TestCounter() to reuse counter-filling logic in cloudwatch_test.go
Alejandro Pedraza
6 years ago
13 | 13 | // TestCounter puts some deltas through the counter, and then calls the value |
14 | 14 | // func to check that the counter has the correct final value. |
15 | 15 | 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 { | |
16 | 26 | a := rand.Perm(100) |
17 | 27 | n := rand.Intn(len(a)) |
18 | 28 | |
22 | 32 | counter.Add(f) |
23 | 33 | want += f |
24 | 34 | } |
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 | |
31 | 36 | } |
32 | 37 | |
33 | 38 | // TestGauge puts some values through the gauge, and then calls the value func |