Dep helper (#2151)

* Add dep task to update go dependencies

* Update go dependencies
This commit is contained in:
Manuel Alejandro de Brito Fontes
2018-09-29 19:47:07 -03:00
committed by Miek Gieben
parent 8f8b81f56b
commit 0e8977761d
764 changed files with 172 additions and 267451 deletions

View File

@@ -1,148 +0,0 @@
package ext_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/mocktracer"
)
func TestPeerTags(t *testing.T) {
if ext.PeerService != "peer.service" {
t.Fatalf("Invalid PeerService %v", ext.PeerService)
}
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace")
ext.PeerService.Set(span, "my-service")
ext.PeerAddress.Set(span, "my-hostname:8080")
ext.PeerHostname.Set(span, "my-hostname")
ext.PeerHostIPv4.Set(span, uint32(127<<24|1))
ext.PeerHostIPv6.Set(span, "::")
ext.PeerPort.Set(span, uint16(8080))
ext.SamplingPriority.Set(span, uint16(1))
ext.SpanKind.Set(span, ext.SpanKindRPCServerEnum)
ext.SpanKindRPCClient.Set(span)
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"peer.service": "my-service",
"peer.address": "my-hostname:8080",
"peer.hostname": "my-hostname",
"peer.ipv4": uint32(127<<24 | 1),
"peer.ipv6": "::",
"peer.port": uint16(8080),
"span.kind": ext.SpanKindRPCClientEnum,
}, rawSpan.Tags())
assert.True(t, span.Context().(mocktracer.MockSpanContext).Sampled)
ext.SamplingPriority.Set(span, uint16(0))
assert.False(t, span.Context().(mocktracer.MockSpanContext).Sampled)
}
func TestHTTPTags(t *testing.T) {
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace", ext.SpanKindRPCServer)
ext.HTTPUrl.Set(span, "test.biz/uri?protocol=false")
ext.HTTPMethod.Set(span, "GET")
ext.HTTPStatusCode.Set(span, 301)
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"http.url": "test.biz/uri?protocol=false",
"http.method": "GET",
"http.status_code": uint16(301),
"span.kind": ext.SpanKindRPCServerEnum,
}, rawSpan.Tags())
}
func TestDBTags(t *testing.T) {
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace", ext.SpanKindRPCClient)
ext.DBInstance.Set(span, "127.0.0.1:3306/customers")
ext.DBStatement.Set(span, "SELECT * FROM user_table")
ext.DBType.Set(span, "sql")
ext.DBUser.Set(span, "customer_user")
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"db.instance": "127.0.0.1:3306/customers",
"db.statement": "SELECT * FROM user_table",
"db.type": "sql",
"db.user": "customer_user",
"span.kind": ext.SpanKindRPCClientEnum,
}, rawSpan.Tags())
}
func TestMiscTags(t *testing.T) {
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace")
ext.Component.Set(span, "my-awesome-library")
ext.SamplingPriority.Set(span, 1)
ext.Error.Set(span, true)
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"component": "my-awesome-library",
"error": true,
}, rawSpan.Tags())
}
func TestRPCServerOption(t *testing.T) {
tracer := mocktracer.New()
parent := tracer.StartSpan("my-trace")
parent.SetBaggageItem("bag", "gage")
carrier := opentracing.HTTPHeadersCarrier{}
err := tracer.Inject(parent.Context(), opentracing.HTTPHeaders, carrier)
if err != nil {
t.Fatal(err)
}
parCtx, err := tracer.Extract(opentracing.HTTPHeaders, carrier)
if err != nil {
t.Fatal(err)
}
tracer.StartSpan("my-child", ext.RPCServerOption(parCtx)).Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"span.kind": ext.SpanKindRPCServerEnum,
}, rawSpan.Tags())
assert.Equal(t, map[string]string{
"bag": "gage",
}, rawSpan.Context().(mocktracer.MockSpanContext).Baggage)
}
func TestMessageBusProducerTags(t *testing.T) {
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace", ext.SpanKindProducer)
ext.MessageBusDestination.Set(span, "topic name")
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"message_bus.destination": "topic name",
"span.kind": ext.SpanKindProducerEnum,
}, rawSpan.Tags())
}
func TestMessageBusConsumerTags(t *testing.T) {
tracer := mocktracer.New()
span := tracer.StartSpan("my-trace", ext.SpanKindConsumer)
ext.MessageBusDestination.Set(span, "topic name")
span.Finish()
rawSpan := tracer.FinishedSpans()[0]
assert.Equal(t, map[string]interface{}{
"message_bus.destination": "topic name",
"span.kind": ext.SpanKindConsumerEnum,
}, rawSpan.Tags())
}

View File

@@ -1,81 +0,0 @@
package opentracing
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestContextWithSpan(t *testing.T) {
span := &noopSpan{}
ctx := ContextWithSpan(context.Background(), span)
span2 := SpanFromContext(ctx)
if span != span2 {
t.Errorf("Not the same span returned from context, expected=%+v, actual=%+v", span, span2)
}
ctx = context.Background()
span2 = SpanFromContext(ctx)
if span2 != nil {
t.Errorf("Expected nil span, found %+v", span2)
}
ctx = ContextWithSpan(ctx, span)
span2 = SpanFromContext(ctx)
if span != span2 {
t.Errorf("Not the same span returned from context, expected=%+v, actual=%+v", span, span2)
}
}
func TestStartSpanFromContext(t *testing.T) {
testTracer := testTracer{}
// Test the case where there *is* a Span in the Context.
{
parentSpan := &testSpan{}
parentCtx := ContextWithSpan(context.Background(), parentSpan)
childSpan, childCtx := startSpanFromContextWithTracer(parentCtx, testTracer, "child")
if !childSpan.Context().(testSpanContext).HasParent {
t.Errorf("Failed to find parent: %v", childSpan)
}
if !childSpan.(testSpan).Equal(SpanFromContext(childCtx)) {
t.Errorf("Unable to find child span in context: %v", childCtx)
}
}
// Test the case where there *is not* a Span in the Context.
{
emptyCtx := context.Background()
childSpan, childCtx := startSpanFromContextWithTracer(emptyCtx, testTracer, "child")
if childSpan.Context().(testSpanContext).HasParent {
t.Errorf("Should not have found parent: %v", childSpan)
}
if !childSpan.(testSpan).Equal(SpanFromContext(childCtx)) {
t.Errorf("Unable to find child span in context: %v", childCtx)
}
}
}
func TestStartSpanFromContextOptions(t *testing.T) {
testTracer := testTracer{}
// Test options are passed to tracer
startTime := time.Now().Add(-10 * time.Second) // ten seconds ago
span, ctx := startSpanFromContextWithTracer(
context.Background(), testTracer, "parent", StartTime(startTime), Tag{"component", "test"})
assert.Equal(t, "test", span.(testSpan).Tags["component"])
assert.Equal(t, startTime, span.(testSpan).StartTime)
// Test it also works for a child span
childStartTime := startTime.Add(3 * time.Second)
childSpan, _ := startSpanFromContextWithTracer(
ctx, testTracer, "child", StartTime(childStartTime))
assert.Equal(t, childSpan.(testSpan).Tags["component"], nil)
assert.Equal(t, childSpan.(testSpan).StartTime, childStartTime)
}

View File

@@ -1,39 +0,0 @@
package log
import (
"fmt"
"testing"
)
func TestFieldString(t *testing.T) {
testCases := []struct {
field Field
expected string
}{
{
field: String("key", "value"),
expected: "key:value",
},
{
field: Bool("key", true),
expected: "key:true",
},
{
field: Int("key", 5),
expected: "key:5",
},
{
field: Error(fmt.Errorf("err msg")),
expected: "error:err msg",
},
{
field: Error(nil),
expected: "error:<nil>",
},
}
for i, tc := range testCases {
if str := tc.field.String(); str != tc.expected {
t.Errorf("%d: expected '%s', got '%s'", i, tc.expected, str)
}
}
}

View File

@@ -1,31 +0,0 @@
package opentracing
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestChildOfAndFollowsFrom(t *testing.T) {
tests := []struct {
newOpt func(SpanContext) SpanReference
refType SpanReferenceType
name string
}{
{ChildOf, ChildOfRef, "ChildOf"},
{FollowsFrom, FollowsFromRef, "FollowsFrom"},
}
for _, test := range tests {
opts := new(StartSpanOptions)
test.newOpt(nil).Apply(opts)
require.Nil(t, opts.References, "%s(nil) must not append a reference", test.name)
ctx := new(noopSpanContext)
test.newOpt(ctx).Apply(opts)
require.Equal(t, []SpanReference{
SpanReference{ReferencedContext: ctx, Type: test.refType},
}, opts.References, "%s(ctx) must append a reference", test.name)
}
}

View File

@@ -1,93 +0,0 @@
package opentracing
import (
"net/http"
"strconv"
"testing"
)
const testHeaderPrefix = "testprefix-"
func TestTextMapCarrierInject(t *testing.T) {
m := make(map[string]string)
m["NotOT"] = "blah"
m["opname"] = "AlsoNotOT"
tracer := testTracer{}
span := tracer.StartSpan("someSpan")
fakeID := span.Context().(testSpanContext).FakeID
carrier := TextMapCarrier(m)
if err := span.Tracer().Inject(span.Context(), TextMap, carrier); err != nil {
t.Fatal(err)
}
if len(m) != 3 {
t.Errorf("Unexpected header length: %v", len(m))
}
// The prefix comes from just above; the suffix comes from
// testTracer.Inject().
if m["testprefix-fakeid"] != strconv.Itoa(fakeID) {
t.Errorf("Could not find fakeid at expected key")
}
}
func TestTextMapCarrierExtract(t *testing.T) {
m := make(map[string]string)
m["NotOT"] = "blah"
m["opname"] = "AlsoNotOT"
m["testprefix-fakeid"] = "42"
tracer := testTracer{}
carrier := TextMapCarrier(m)
extractedContext, err := tracer.Extract(TextMap, carrier)
if err != nil {
t.Fatal(err)
}
if extractedContext.(testSpanContext).FakeID != 42 {
t.Errorf("Failed to read testprefix-fakeid correctly")
}
}
func TestHTTPHeaderInject(t *testing.T) {
h := http.Header{}
h.Add("NotOT", "blah")
h.Add("opname", "AlsoNotOT")
tracer := testTracer{}
span := tracer.StartSpan("someSpan")
fakeID := span.Context().(testSpanContext).FakeID
// Use HTTPHeadersCarrier to wrap around `h`.
carrier := HTTPHeadersCarrier(h)
if err := span.Tracer().Inject(span.Context(), HTTPHeaders, carrier); err != nil {
t.Fatal(err)
}
if len(h) != 3 {
t.Errorf("Unexpected header length: %v", len(h))
}
// The prefix comes from just above; the suffix comes from
// testTracer.Inject().
if h.Get("testprefix-fakeid") != strconv.Itoa(fakeID) {
t.Errorf("Could not find fakeid at expected key")
}
}
func TestHTTPHeaderExtract(t *testing.T) {
h := http.Header{}
h.Add("NotOT", "blah")
h.Add("opname", "AlsoNotOT")
h.Add("testprefix-fakeid", "42")
tracer := testTracer{}
// Use HTTPHeadersCarrier to wrap around `h`.
carrier := HTTPHeadersCarrier(h)
spanContext, err := tracer.Extract(HTTPHeaders, carrier)
if err != nil {
t.Fatal(err)
}
if spanContext.(testSpanContext).FakeID != 42 {
t.Errorf("Failed to read testprefix-fakeid correctly")
}
}

View File

@@ -1,138 +0,0 @@
package opentracing
import (
"strconv"
"strings"
"time"
"github.com/opentracing/opentracing-go/log"
)
const testHTTPHeaderPrefix = "testprefix-"
// testTracer is a most-noop Tracer implementation that makes it possible for
// unittests to verify whether certain methods were / were not called.
type testTracer struct{}
var fakeIDSource = 1
func nextFakeID() int {
fakeIDSource++
return fakeIDSource
}
type testSpanContext struct {
HasParent bool
FakeID int
}
func (n testSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {}
type testSpan struct {
spanContext testSpanContext
OperationName string
StartTime time.Time
Tags map[string]interface{}
}
func (n testSpan) Equal(os Span) bool {
other, ok := os.(testSpan)
if !ok {
return false
}
if n.spanContext != other.spanContext {
return false
}
if n.OperationName != other.OperationName {
return false
}
if !n.StartTime.Equal(other.StartTime) {
return false
}
if len(n.Tags) != len(other.Tags) {
return false
}
for k, v := range n.Tags {
if ov, ok := other.Tags[k]; !ok || ov != v {
return false
}
}
return true
}
// testSpan:
func (n testSpan) Context() SpanContext { return n.spanContext }
func (n testSpan) SetTag(key string, value interface{}) Span { return n }
func (n testSpan) Finish() {}
func (n testSpan) FinishWithOptions(opts FinishOptions) {}
func (n testSpan) LogFields(fields ...log.Field) {}
func (n testSpan) LogKV(kvs ...interface{}) {}
func (n testSpan) SetOperationName(operationName string) Span { return n }
func (n testSpan) Tracer() Tracer { return testTracer{} }
func (n testSpan) SetBaggageItem(key, val string) Span { return n }
func (n testSpan) BaggageItem(key string) string { return "" }
func (n testSpan) LogEvent(event string) {}
func (n testSpan) LogEventWithPayload(event string, payload interface{}) {}
func (n testSpan) Log(data LogData) {}
// StartSpan belongs to the Tracer interface.
func (n testTracer) StartSpan(operationName string, opts ...StartSpanOption) Span {
sso := StartSpanOptions{}
for _, o := range opts {
o.Apply(&sso)
}
return n.startSpanWithOptions(operationName, sso)
}
func (n testTracer) startSpanWithOptions(name string, opts StartSpanOptions) Span {
fakeID := nextFakeID()
if len(opts.References) > 0 {
fakeID = opts.References[0].ReferencedContext.(testSpanContext).FakeID
}
return testSpan{
OperationName: name,
StartTime: opts.StartTime,
Tags: opts.Tags,
spanContext: testSpanContext{
HasParent: len(opts.References) > 0,
FakeID: fakeID,
},
}
}
// Inject belongs to the Tracer interface.
func (n testTracer) Inject(sp SpanContext, format interface{}, carrier interface{}) error {
spanContext := sp.(testSpanContext)
switch format {
case HTTPHeaders, TextMap:
carrier.(TextMapWriter).Set(testHTTPHeaderPrefix+"fakeid", strconv.Itoa(spanContext.FakeID))
return nil
}
return ErrUnsupportedFormat
}
// Extract belongs to the Tracer interface.
func (n testTracer) Extract(format interface{}, carrier interface{}) (SpanContext, error) {
switch format {
case HTTPHeaders, TextMap:
// Just for testing purposes... generally not a worthwhile thing to
// propagate.
sm := testSpanContext{}
err := carrier.(TextMapReader).ForeachKey(func(key, val string) error {
switch strings.ToLower(key) {
case testHTTPHeaderPrefix + "fakeid":
i, err := strconv.Atoi(val)
if err != nil {
return err
}
sm.FakeID = i
}
return nil
})
return sm, err
}
return nil, ErrSpanContextNotFound
}