Files
ent/dialect/gremlin/ocgremlin/client_test.go
Ariel Mashraki bd07c86b60 all: add license header to all go files
Summary:
Used addlicense to generate this:
 addlicense -c "Facebook Inc" -f license_header .

example was taken from: https://github.com/facebook/litho/blob/master/lib/soloader/BUCK

Reviewed By: alexsn

Differential Revision: D17070152

fbshipit-source-id: e7b91398d7f6181727be3400c1872ad5f28e38ed
2019-08-27 04:48:28 -07:00

75 lines
1.7 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package ocgremlin
import (
"context"
"errors"
"testing"
"github.com/facebookincubator/ent/dialect/gremlin"
"github.com/stretchr/testify/mock"
"go.opencensus.io/trace"
)
type mockExporter struct {
mock.Mock
}
func (e *mockExporter) ExportSpan(s *trace.SpanData) {
e.Called(s)
}
func TestTransportOptions(t *testing.T) {
tests := []struct {
name string
spanName string
wantName string
}{
{
name: "Default formatter",
wantName: "gremlin:traversal",
},
{
name: "Custom formatter",
spanName: "tester",
wantName: "tester",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
var exporter mockExporter
exporter.On(
"ExportSpan",
mock.MatchedBy(func(s *trace.SpanData) bool { return s.Name == tt.wantName })).
Once()
defer exporter.AssertExpectations(t)
trace.RegisterExporter(&exporter)
defer trace.UnregisterExporter(&exporter)
transport := &mockTransport{}
transport.On("RoundTrip", mock.Anything, mock.Anything).
Return(nil, errors.New("noop")).
Once()
defer transport.AssertExpectations(t)
rt := &Transport{
Base: transport,
GetStartOptions: func(context.Context, *gremlin.Request) trace.StartOptions {
return trace.StartOptions{Sampler: trace.AlwaysSample()}
},
}
if tt.spanName != "" {
rt.FormatSpanName = func(context.Context, *gremlin.Request) string {
return tt.spanName
}
}
_, _ = rt.RoundTrip(context.Background(), gremlin.NewEvalRequest("g.E()"))
})
}
}