1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:38:33 -06:00

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 <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Cottrell 2019-11-22 13:41:57 -05:00
parent c02aa52d2b
commit 2a6ccf25d7

View File

@ -5,10 +5,10 @@
package ocagent_test
import (
"bytes"
"context"
"encoding/json"
"errors"
"reflect"
"testing"
"golang.org/x/tools/internal/telemetry"
@ -207,18 +207,20 @@ func TestConvert_annotation(t *testing.T) {
checkJSON(t, got, []byte(tt.want))
})
}
}
func checkJSON(t *testing.T, got, want []byte) {
// compare the decoded form, to allow for formatting differences
var g, w map[string]interface{}
if err := json.Unmarshal(got, &g); err != nil {
// compare the compact form, to allow for formatting differences
g := &bytes.Buffer{}
if err := json.Compact(g, got); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(want, &w); err != nil {
w := &bytes.Buffer{}
if err := json.Compact(w, want); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(g, w) {
if g.String() != w.String() {
t.Fatalf("Got:\n%s\nWant:\n%s", got, want)
}
}