mirror of
https://github.com/golang/go
synced 2024-10-01 03:28:32 -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:
parent
9c44060bd0
commit
947d4aa893
@ -1,6 +1,7 @@
|
|||||||
package ocagent
|
package ocagent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -991,3 +992,8 @@ func TestInfoKeysToLabelKeys(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func marshaled(v interface{}) string {
|
||||||
|
blob, _ := json.MarshalIndent(v, "", " ")
|
||||||
|
return string(blob)
|
||||||
|
}
|
||||||
|
@ -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{}) {
|
func (e *exporter) send(endpoint string, message interface{}) {
|
||||||
blob, err := json.Marshal(message)
|
blob, err := json.Marshal(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package ocagent
|
package ocagent_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -12,6 +12,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/tools/internal/telemetry"
|
"golang.org/x/tools/internal/telemetry"
|
||||||
|
"golang.org/x/tools/internal/telemetry/export/ocagent"
|
||||||
"golang.org/x/tools/internal/telemetry/tag"
|
"golang.org/x/tools/internal/telemetry/tag"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -199,15 +200,25 @@ func TestConvert_annotation(t *testing.T) {
|
|||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := marshaled(convertAnnotation(tt.event(ctx)))
|
got, err := ocagent.EncodeAnnotation(tt.event(ctx))
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if err != nil {
|
||||||
t.Fatalf("Got:\n%s\nWant:\n%s", got, tt.want)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
checkJSON(t, got, []byte(tt.want))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshaled(v interface{}) string {
|
func checkJSON(t *testing.T, got, want []byte) {
|
||||||
blob, _ := json.MarshalIndent(v, "", " ")
|
// compare the decoded form, to allow for formatting differences
|
||||||
return string(blob)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user