-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats_test.go
More file actions
47 lines (42 loc) · 1.08 KB
/
stats_test.go
File metadata and controls
47 lines (42 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package stats
import (
"context"
"testing"
)
func TestMetricsInitted(t *testing.T) {
ctx := context.Background()
bucket := "my/test/metric"
if err := Increment(ctx, bucket); err != RequestMetricsNotInitted {
t.Errorf("Expected error %s, got %v", RequestMetricsNotInitted, err)
}
ctx = requestContextUsingMetrics()
if err := Increment(ctx, bucket); err != nil {
t.Errorf("Expected no error, got %v", err)
}
}
var nameChecks = []struct {
name string
err error
}{
{"my/test/metric", nil},
{"", IllegalMetricName},
{"with/double//slashes.name", IllegalMetricName},
{"ends/with/.", IllegalMetricName},
{"illegal/char&", IllegalMetricName},
}
func TestNames(t *testing.T) {
ctx := requestContextUsingMetrics()
for _, test := range nameChecks {
err := Increment(ctx, test.name)
if err != test.err {
t.Errorf("Test metric name %s: expected %v, got %v", test.name, test.err, err)
continue
}
}
}
func requestContextUsingMetrics() context.Context {
// just to make the example pretty
ctx := context.Background()
ctx = statsToContext(ctx, newRequestStats())
return ctx
}