Skip to content

Commit 023c5ee

Browse files
Ian Cottrellianthehat
Ian Cottrell
authored andcommitted
internal/lsp: change annotation tests to json
This checks against the json form rather than the wire structs This will allow the encoding method to change without the test changing. Change-Id: Iefe84cc03bc6e82627acd031e0991c31b4fed315 Reviewed-on: https://go-review.googlesource.com/c/tools/+/206884 Run-TryBot: Ian Cottrell <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 77e3bb0 commit 023c5ee

File tree

1 file changed

+108
-57
lines changed

1 file changed

+108
-57
lines changed

internal/telemetry/export/ocagent/ocagent_test.go

+108-57
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ import (
1111
"testing"
1212

1313
"golang.org/x/tools/internal/telemetry"
14-
"golang.org/x/tools/internal/telemetry/export/ocagent/wire"
1514
"golang.org/x/tools/internal/telemetry/tag"
1615
)
1716

1817
func TestConvert_annotation(t *testing.T) {
1918
tests := []struct {
2019
name string
2120
event telemetry.Event
22-
want *wire.Annotation
21+
want string
2322
}{
2423
{
2524
name: "no tags",
26-
want: nil,
25+
want: "null",
2726
},
2827
{
2928
name: "description no error",
@@ -33,14 +32,20 @@ func TestConvert_annotation(t *testing.T) {
3332
tag.Of("db", "godb"),
3433
},
3534
},
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+
}`,
4449
},
4550

4651
{
@@ -52,15 +57,25 @@ func TestConvert_annotation(t *testing.T) {
5257
tag.Of("db", "godb"),
5358
},
5459
},
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+
}`,
6479
},
6580
{
6681
name: "no description, but error",
@@ -70,14 +85,20 @@ func TestConvert_annotation(t *testing.T) {
7085
tag.Of("db", "godb"),
7186
},
7287
},
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+
}`,
81102
},
82103
{
83104
name: "enumerate all attribute types",
@@ -106,41 +127,71 @@ func TestConvert_annotation(t *testing.T) {
106127
tag.Of("max_hops", uint64(0xffffff)),
107128
},
108129
},
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+
}`,
136187
},
137188
}
138189

139190
for _, tt := range tests {
140191
t.Run(tt.name, func(t *testing.T) {
141-
got := convertAnnotation(tt.event)
192+
got := marshaled(convertAnnotation(tt.event))
142193
if !reflect.DeepEqual(got, tt.want) {
143-
t.Fatalf("Got:\n%s\nWant:\n%s", marshaled(got), marshaled(tt.want))
194+
t.Fatalf("Got:\n%s\nWant:\n%s", got, tt.want)
144195
}
145196
})
146197
}

0 commit comments

Comments
 (0)