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

internal/lsp: make the ocagent test external

They now call a public encode function and have no knowledge of the private
conversion functions or any of the contents of the wire package.

Change-Id: I4364a4d9d1efe4bc872627556e537936b5880231
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207903
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-18 10:30:03 -05:00 committed by Emmanuel Odeke
parent 9c44060bd0
commit 947d4aa893
3 changed files with 28 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package ocagent
import (
"encoding/json"
"reflect"
"testing"
"time"
@ -991,3 +992,8 @@ func TestInfoKeysToLabelKeys(t *testing.T) {
})
}
}
func marshaled(v interface{}) string {
blob, _ := json.MarshalIndent(v, "", " ")
return string(blob)
}

View File

@ -144,6 +144,10 @@ func (e *exporter) Flush() {
}
}
func EncodeAnnotation(a telemetry.Event) ([]byte, error) {
return json.Marshal(convertAnnotation(a))
}
func (e *exporter) send(endpoint string, message interface{}) {
blob, err := json.Marshal(message)
if err != nil {

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ocagent
package ocagent_test
import (
"context"
@ -12,6 +12,7 @@ import (
"testing"
"golang.org/x/tools/internal/telemetry"
"golang.org/x/tools/internal/telemetry/export/ocagent"
"golang.org/x/tools/internal/telemetry/tag"
)
@ -199,15 +200,25 @@ func TestConvert_annotation(t *testing.T) {
ctx := context.TODO()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := marshaled(convertAnnotation(tt.event(ctx)))
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("Got:\n%s\nWant:\n%s", got, tt.want)
got, err := ocagent.EncodeAnnotation(tt.event(ctx))
if err != nil {
t.Fatal(err)
}
checkJSON(t, got, []byte(tt.want))
})
}
}
func marshaled(v interface{}) string {
blob, _ := json.MarshalIndent(v, "", " ")
return string(blob)
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 {
t.Fatal(err)
}
if err := json.Unmarshal(want, &w); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(g, w) {
t.Fatalf("Got:\n%s\nWant:\n%s", got, want)
}
}