@@ -11,19 +11,18 @@ import (
11
11
"testing"
12
12
13
13
"golang.org/x/tools/internal/telemetry"
14
- "golang.org/x/tools/internal/telemetry/export/ocagent/wire"
15
14
"golang.org/x/tools/internal/telemetry/tag"
16
15
)
17
16
18
17
func TestConvert_annotation (t * testing.T ) {
19
18
tests := []struct {
20
19
name string
21
20
event telemetry.Event
22
- want * wire. Annotation
21
+ want string
23
22
}{
24
23
{
25
24
name : "no tags" ,
26
- want : nil ,
25
+ want : "null" ,
27
26
},
28
27
{
29
28
name : "description no error" ,
@@ -33,14 +32,20 @@ func TestConvert_annotation(t *testing.T) {
33
32
tag .Of ("db" , "godb" ),
34
33
},
35
34
},
36
- want : & wire.Annotation {
37
- Description : & wire.TruncatableString {Value : "cache miss" },
38
- Attributes : & wire.Attributes {
39
- AttributeMap : map [string ]wire.Attribute {
40
- "db" : wire.StringAttribute {StringValue : & wire.TruncatableString {Value : "godb" }},
41
- },
42
- },
43
- },
35
+ want : `{
36
+ "description": {
37
+ "value": "cache miss"
38
+ },
39
+ "attributes": {
40
+ "attributeMap": {
41
+ "db": {
42
+ "stringValue": {
43
+ "value": "godb"
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }` ,
44
49
},
45
50
46
51
{
@@ -52,15 +57,25 @@ func TestConvert_annotation(t *testing.T) {
52
57
tag .Of ("db" , "godb" ),
53
58
},
54
59
},
55
- want : & wire.Annotation {
56
- Description : & wire.TruncatableString {Value : "cache miss" },
57
- Attributes : & wire.Attributes {
58
- AttributeMap : map [string ]wire.Attribute {
59
- "Error" : wire.StringAttribute {StringValue : & wire.TruncatableString {Value : "no network connectivity" }},
60
- "db" : wire.StringAttribute {StringValue : & wire.TruncatableString {Value : "godb" }},
61
- },
62
- },
63
- },
60
+ want : `{
61
+ "description": {
62
+ "value": "cache miss"
63
+ },
64
+ "attributes": {
65
+ "attributeMap": {
66
+ "Error": {
67
+ "stringValue": {
68
+ "value": "no network connectivity"
69
+ }
70
+ },
71
+ "db": {
72
+ "stringValue": {
73
+ "value": "godb"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }` ,
64
79
},
65
80
{
66
81
name : "no description, but error" ,
@@ -70,14 +85,20 @@ func TestConvert_annotation(t *testing.T) {
70
85
tag .Of ("db" , "godb" ),
71
86
},
72
87
},
73
- want : & wire.Annotation {
74
- Description : & wire.TruncatableString {Value : "no network connectivity" },
75
- Attributes : & wire.Attributes {
76
- AttributeMap : map [string ]wire.Attribute {
77
- "db" : wire.StringAttribute {StringValue : & wire.TruncatableString {Value : "godb" }},
78
- },
79
- },
80
- },
88
+ want : `{
89
+ "description": {
90
+ "value": "no network connectivity"
91
+ },
92
+ "attributes": {
93
+ "attributeMap": {
94
+ "db": {
95
+ "stringValue": {
96
+ "value": "godb"
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }` ,
81
102
},
82
103
{
83
104
name : "enumerate all attribute types" ,
@@ -106,41 +127,71 @@ func TestConvert_annotation(t *testing.T) {
106
127
tag .Of ("max_hops" , uint64 (0xffffff )),
107
128
},
108
129
},
109
- want : & wire.Annotation {
110
- Description : & wire.TruncatableString {Value : "cache miss" },
111
- Attributes : & wire.Attributes {
112
- AttributeMap : map [string ]wire.Attribute {
113
- "db" : wire.StringAttribute {StringValue : & wire.TruncatableString {Value : "godb" }},
114
-
115
- "age" : wire.DoubleAttribute {DoubleValue : 0.456 },
116
- "ttl" : wire.DoubleAttribute {DoubleValue : 5000.0 },
117
- "expiry_ms" : wire.DoubleAttribute {DoubleValue : 1e3 },
118
-
119
- "retry" : wire.BoolAttribute {BoolValue : false },
120
- "stale" : wire.BoolAttribute {BoolValue : true },
121
-
122
- "max" : wire.IntAttribute {IntValue : 0x7fff },
123
- "opcode" : wire.IntAttribute {IntValue : 0x7e },
124
- "base" : wire.IntAttribute {IntValue : 1 << 9 },
125
- "checksum" : wire.IntAttribute {IntValue : 0x11f7e294 },
126
- "mode" : wire.IntAttribute {IntValue : 0644 },
127
-
128
- "min" : wire.IntAttribute {IntValue : 1 },
129
- "mix" : wire.IntAttribute {IntValue : 44 },
130
- "port" : wire.IntAttribute {IntValue : 55678 },
131
- "min_hops" : wire.IntAttribute {IntValue : 1 << 9 },
132
- "max_hops" : wire.IntAttribute {IntValue : 0xffffff },
133
- },
134
- },
135
- },
130
+ want : `{
131
+ "description": {
132
+ "value": "cache miss"
133
+ },
134
+ "attributes": {
135
+ "attributeMap": {
136
+ "age": {
137
+ "doubleValue": 0.456
138
+ },
139
+ "base": {
140
+ "intValue": 512
141
+ },
142
+ "checksum": {
143
+ "intValue": 301458068
144
+ },
145
+ "db": {
146
+ "stringValue": {
147
+ "value": "godb"
148
+ }
149
+ },
150
+ "expiry_ms": {
151
+ "doubleValue": 1000
152
+ },
153
+ "max": {
154
+ "intValue": 32767
155
+ },
156
+ "max_hops": {
157
+ "intValue": 16777215
158
+ },
159
+ "min": {
160
+ "intValue": 1
161
+ },
162
+ "min_hops": {
163
+ "intValue": 512
164
+ },
165
+ "mix": {
166
+ "intValue": 44
167
+ },
168
+ "mode": {
169
+ "intValue": 420
170
+ },
171
+ "opcode": {
172
+ "intValue": 126
173
+ },
174
+ "port": {
175
+ "intValue": 55678
176
+ },
177
+ "retry": {},
178
+ "stale": {
179
+ "boolValue": true
180
+ },
181
+ "ttl": {
182
+ "doubleValue": 5000
183
+ }
184
+ }
185
+ }
186
+ }` ,
136
187
},
137
188
}
138
189
139
190
for _ , tt := range tests {
140
191
t .Run (tt .name , func (t * testing.T ) {
141
- got := convertAnnotation (tt .event )
192
+ got := marshaled ( convertAnnotation (tt .event ) )
142
193
if ! reflect .DeepEqual (got , tt .want ) {
143
- t .Fatalf ("Got:\n %s\n Want:\n %s" , marshaled ( got ), marshaled ( tt .want ) )
194
+ t .Fatalf ("Got:\n %s\n Want:\n %s" , got , tt .want )
144
195
}
145
196
})
146
197
}
0 commit comments