...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ochttp
16
17 import (
18 "reflect"
19 "strings"
20 "testing"
21
22 "go.opencensus.io/stats"
23 "go.opencensus.io/stats/view"
24 "go.opencensus.io/tag"
25 )
26
27 func TestClientViews(t *testing.T) {
28 for _, v := range []*view.View{
29 ClientSentBytesDistribution,
30 ClientReceivedBytesDistribution,
31 ClientRoundtripLatencyDistribution,
32 ClientCompletedCount,
33 } {
34
35 if v.Measure == nil {
36 t.Fatalf("nil measure: %v", v)
37 }
38 if m := v.Measure.Name(); !strings.HasPrefix(m, "opencensus.io/http/client/") {
39 t.Errorf("Unexpected measure name prefix: %v", v)
40 }
41 if v.Name == "" {
42 t.Errorf("Empty name: %v", v)
43 }
44 if !strings.HasPrefix(v.Name, "opencensus.io/http/client/") {
45 t.Errorf("Unexpected prefix: %s", v.Name)
46 }
47 if v.Description == "" {
48 t.Errorf("Empty description: %s", v.Name)
49 }
50 if !reflect.DeepEqual(v.TagKeys, []tag.Key{KeyClientMethod, KeyClientStatus}) {
51 t.Errorf("Unexpected tags for client view %s: %v", v.Name, v.TagKeys)
52 }
53 if strings.HasSuffix(v.Description, ".") {
54 t.Errorf("View description should not end with a period: %s", v.Name)
55 }
56 }
57 }
58
59 func TestClientTagKeys(t *testing.T) {
60 for _, k := range []tag.Key{
61 KeyClientStatus,
62 KeyClientMethod,
63 KeyClientHost,
64 KeyClientPath,
65 } {
66 if !strings.HasPrefix(k.Name(), "http_client_") {
67 t.Errorf("Unexpected prefix: %s", k.Name())
68 }
69 }
70 }
71
72 func TestClientMeasures(t *testing.T) {
73 for _, m := range []stats.Measure{
74 ClientSentBytes,
75 ClientReceivedBytes,
76 ClientRoundtripLatency,
77 } {
78 if !strings.HasPrefix(m.Name(), "opencensus.io/http/client/") {
79 t.Errorf("Unexpected prefix: %v", m)
80 }
81 if strings.HasSuffix(m.Description(), ".") {
82 t.Errorf("View description should not end with a period: %s", m.Name())
83 }
84 if len(m.Unit()) == 0 {
85 t.Errorf("No unit: %s", m.Name())
86 }
87 }
88 }
89
View as plain text