Skip to content

Commit 2a6ccf2

Browse files
committed
internal/telemetry: compare the compact JSON
It is sufficient to just compact the JSON to compare it rather than bothering to decode it. Change-Id: Ied39d462eec77623187422a9c58f83f8d1630269 Reviewed-on: https://go-review.googlesource.com/c/tools/+/208498 Run-TryBot: Ian Cottrell <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent c02aa52 commit 2a6ccf2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

internal/telemetry/export/ocagent/ocagent_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package ocagent_test
66

77
import (
8+
"bytes"
89
"context"
910
"encoding/json"
1011
"errors"
11-
"reflect"
1212
"testing"
1313

1414
"golang.org/x/tools/internal/telemetry"
@@ -207,18 +207,20 @@ func TestConvert_annotation(t *testing.T) {
207207
checkJSON(t, got, []byte(tt.want))
208208
})
209209
}
210+
210211
}
211212

212213
func checkJSON(t *testing.T, got, want []byte) {
213-
// compare the decoded form, to allow for formatting differences
214-
var g, w map[string]interface{}
215-
if err := json.Unmarshal(got, &g); err != nil {
214+
// compare the compact form, to allow for formatting differences
215+
g := &bytes.Buffer{}
216+
if err := json.Compact(g, got); err != nil {
216217
t.Fatal(err)
217218
}
218-
if err := json.Unmarshal(want, &w); err != nil {
219+
w := &bytes.Buffer{}
220+
if err := json.Compact(w, want); err != nil {
219221
t.Fatal(err)
220222
}
221-
if !reflect.DeepEqual(g, w) {
223+
if g.String() != w.String() {
222224
t.Fatalf("Got:\n%s\nWant:\n%s", got, want)
223225
}
224226
}

0 commit comments

Comments
 (0)