From 2a6ccf25d769ccc6c0b364ff440915b10af1e3cf Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Fri, 22 Nov 2019 13:41:57 -0500 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke --- internal/telemetry/export/ocagent/ocagent_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/telemetry/export/ocagent/ocagent_test.go b/internal/telemetry/export/ocagent/ocagent_test.go index 534c54c316..24dc4375b1 100644 --- a/internal/telemetry/export/ocagent/ocagent_test.go +++ b/internal/telemetry/export/ocagent/ocagent_test.go @@ -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) } }