1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

Remove internal matchers (#6907)

Modifies the only remaining use of the internal matchers to use
`require` and closes #6541
This commit is contained in:
Joe Stephenson
2025-06-17 15:49:22 +01:00
committed by GitHub
parent 2cce189955
commit 94ab03f569
8 changed files with 33 additions and 742 deletions

View File

@@ -1,299 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/expectation.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package matchers provides comparison and matching functionality for tests.
package matchers
import (
"fmt"
"reflect"
"regexp"
"runtime/debug"
"strings"
"testing"
"time"
)
var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`)
type Expectation struct {
t *testing.T
actual interface{}
}
func (e *Expectation) ToEqual(expected interface{}) {
e.verifyExpectedNotNil(expected)
if !reflect.DeepEqual(e.actual, expected) {
e.fatalf("Expected\n\t%v\nto equal\n\t%v", e.actual, expected)
}
}
func (e *Expectation) NotToEqual(expected interface{}) {
e.verifyExpectedNotNil(expected)
if reflect.DeepEqual(e.actual, expected) {
e.fatalf("Expected\n\t%v\nnot to equal\n\t%v", e.actual, expected)
}
}
func (e *Expectation) ToBeNil() {
if e.actual != nil {
e.fatalf("Expected\n\t%v\nto be nil", e.actual)
}
}
func (e *Expectation) NotToBeNil() {
if e.actual == nil {
e.fatalf("Expected\n\t%v\nnot to be nil", e.actual)
}
}
func (e *Expectation) ToBeTrue() {
switch a := e.actual.(type) {
case bool:
if !a {
e.fatalf("Expected\n\t%v\nto be true", e.actual)
}
default:
e.fatalf("Cannot check if non-bool value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) ToBeFalse() {
switch a := e.actual.(type) {
case bool:
if a {
e.fatalf("Expected\n\t%v\nto be false", e.actual)
}
default:
e.fatalf("Cannot check if non-bool value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) NotToPanic() {
switch a := e.actual.(type) {
case func():
func() {
defer func() {
if recovered := recover(); recovered != nil {
e.fatalf("Expected panic\n\t%v\nto have not been raised", recovered)
}
}()
a()
}()
default:
e.fatalf("Cannot check if non-func value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) ToSucceed() {
switch actual := e.actual.(type) {
case error:
if actual != nil {
e.fatalf("Expected error\n\t%v\nto have succeeded", actual)
}
default:
e.fatalf("Cannot check if non-error value\n\t%v\nsucceeded", actual)
}
}
func (e *Expectation) ToMatchError(expected interface{}) {
e.verifyExpectedNotNil(expected)
actual, ok := e.actual.(error)
if !ok {
e.fatalf("Cannot check if non-error value\n\t%v\nmatches error", e.actual)
}
switch expected := expected.(type) {
case error:
if !reflect.DeepEqual(actual, expected) {
e.fatalf("Expected\n\t%v\nto match error\n\t%v", actual, expected)
}
case string:
if actual.Error() != expected {
e.fatalf("Expected\n\t%v\nto match error\n\t%v", actual, expected)
}
default:
e.fatalf("Cannot match\n\t%v\nagainst non-error\n\t%v", actual, expected)
}
}
func (e *Expectation) ToContain(expected interface{}) {
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
switch actualKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", e.actual)
return
}
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
expectedValue = reflect.ValueOf([]interface{}{expected})
}
for i := 0; i < expectedValue.Len(); i++ {
var contained bool
expectedElem := expectedValue.Index(i).Interface()
for j := 0; j < actualValue.Len(); j++ {
if reflect.DeepEqual(actualValue.Index(j).Interface(), expectedElem) {
contained = true
break
}
}
if !contained {
e.fatalf("Expected\n\t%v\nto contain\n\t%v", e.actual, expectedElem)
return
}
}
}
func (e *Expectation) NotToContain(expected interface{}) {
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
switch actualKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", e.actual)
return
}
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
expectedValue = reflect.ValueOf([]interface{}{expected})
}
for i := 0; i < expectedValue.Len(); i++ {
expectedElem := expectedValue.Index(i).Interface()
for j := 0; j < actualValue.Len(); j++ {
if reflect.DeepEqual(actualValue.Index(j).Interface(), expectedElem) {
e.fatalf("Expected\n\t%v\nnot to contain\n\t%v", e.actual, expectedElem)
return
}
}
}
}
func (e *Expectation) ToMatchInAnyOrder(expected interface{}) {
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", expected)
return
}
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
if actualKind != expectedKind {
e.fatalf("Expected\n\t%v\nto be the same type as\n\t%v", e.actual, expected)
return
}
if actualValue.Len() != expectedValue.Len() {
e.fatalf("Expected\n\t%v\nto have the same length as\n\t%v", e.actual, expected)
return
}
var unmatched []interface{}
for i := 0; i < expectedValue.Len(); i++ {
unmatched = append(unmatched, expectedValue.Index(i).Interface())
}
for i := 0; i < actualValue.Len(); i++ {
var found bool
for j, elem := range unmatched {
if reflect.DeepEqual(actualValue.Index(i).Interface(), elem) {
found = true
unmatched = append(unmatched[:j], unmatched[j+1:]...)
break
}
}
if !found {
e.fatalf("Expected\n\t%v\nto contain the same elements as\n\t%v", e.actual, expected)
}
}
}
func (e *Expectation) ToBeTemporally(matcher TemporalMatcher, compareTo interface{}) {
if actual, ok := e.actual.(time.Time); ok {
ct, ok := compareTo.(time.Time)
if !ok {
e.fatalf("Cannot compare to non-temporal value\n\t%v", compareTo)
return
}
switch matcher {
case Before:
if !actual.Before(ct) {
e.fatalf("Expected\n\t%v\nto be temporally before\n\t%v", e.actual, compareTo)
}
case BeforeOrSameTime:
if actual.After(ct) {
e.fatalf("Expected\n\t%v\nto be temporally before or at the same time as\n\t%v", e.actual, compareTo)
}
case After:
if !actual.After(ct) {
e.fatalf("Expected\n\t%v\nto be temporally after\n\t%v", e.actual, compareTo)
}
case AfterOrSameTime:
if actual.Before(ct) {
e.fatalf("Expected\n\t%v\nto be temporally after or at the same time as\n\t%v", e.actual, compareTo)
}
default:
e.fatalf("Cannot compare times with unexpected temporal matcher")
}
return
}
e.fatalf("Cannot compare non-temporal value\n\t%v", e.actual)
}
func (e *Expectation) verifyExpectedNotNil(expected interface{}) {
if expected == nil {
e.fatalf("Refusing to compare with <nil>. Use `ToBeNil` or `NotToBeNil` instead.")
}
}
func (e *Expectation) fatalf(format string, a ...any) {
// Prune the stack trace so that it's easier to see relevant lines
stack := strings.Split(string(debug.Stack()), "\n")
var prunedStack []string
for _, line := range stack {
if !stackTracePruneRE.MatchString(line) {
prunedStack = append(prunedStack, line)
}
}
msg := fmt.Sprintf(format, a...)
e.t.Fatalf("\n%s\n%s\n", strings.Join(prunedStack, "\n"), msg)
}

View File

@@ -1,28 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/expecter.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package matchers
import (
"testing"
)
type Expecter struct {
t *testing.T
}
func NewExpecter(t *testing.T) *Expecter {
return &Expecter{
t: t,
}
}
func (a *Expecter) Expect(actual interface{}) *Expectation {
return &Expectation{
t: a.t,
actual: actual,
}
}

View File

@@ -1,17 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/temporal_matcher.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package matchers
type TemporalMatcher byte
//nolint:revive // ignoring missing comments for unexported constants in an internal package
const (
Before TemporalMatcher = iota
BeforeOrSameTime
After
AfterOrSameTime
)

View File

@@ -1,9 +0,0 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package internal provides internal functionality for the sdk package.
package internal // import "go.opentelemetry.io/otel/sdk/internal"
//go:generate gotmpl --body=../../internal/shared/matchers/expectation.go.tmpl "--data={}" --out=matchers/expectation.go
//go:generate gotmpl --body=../../internal/shared/matchers/expecter.go.tmpl "--data={}" --out=matchers/expecter.go
//go:generate gotmpl --body=../../internal/shared/matchers/temporal_matcher.go.tmpl "--data={}" --out=matchers/temporal_matcher.go

View File

@@ -1,299 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/expectation.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package matchers provides comparison and matching functionality for tests.
package matchers // import "go.opentelemetry.io/otel/sdk/internal/matchers"
import (
"fmt"
"reflect"
"regexp"
"runtime/debug"
"strings"
"testing"
"time"
)
var stackTracePruneRE = regexp.MustCompile(`runtime\/debug|testing|internal\/matchers`)
type Expectation struct {
t *testing.T
actual interface{}
}
func (e *Expectation) ToEqual(expected interface{}) {
e.verifyExpectedNotNil(expected)
if !reflect.DeepEqual(e.actual, expected) {
e.fatalf("Expected\n\t%v\nto equal\n\t%v", e.actual, expected)
}
}
func (e *Expectation) NotToEqual(expected interface{}) {
e.verifyExpectedNotNil(expected)
if reflect.DeepEqual(e.actual, expected) {
e.fatalf("Expected\n\t%v\nnot to equal\n\t%v", e.actual, expected)
}
}
func (e *Expectation) ToBeNil() {
if e.actual != nil {
e.fatalf("Expected\n\t%v\nto be nil", e.actual)
}
}
func (e *Expectation) NotToBeNil() {
if e.actual == nil {
e.fatalf("Expected\n\t%v\nnot to be nil", e.actual)
}
}
func (e *Expectation) ToBeTrue() {
switch a := e.actual.(type) {
case bool:
if !a {
e.fatalf("Expected\n\t%v\nto be true", e.actual)
}
default:
e.fatalf("Cannot check if non-bool value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) ToBeFalse() {
switch a := e.actual.(type) {
case bool:
if a {
e.fatalf("Expected\n\t%v\nto be false", e.actual)
}
default:
e.fatalf("Cannot check if non-bool value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) NotToPanic() {
switch a := e.actual.(type) {
case func():
func() {
defer func() {
if recovered := recover(); recovered != nil {
e.fatalf("Expected panic\n\t%v\nto have not been raised", recovered)
}
}()
a()
}()
default:
e.fatalf("Cannot check if non-func value\n\t%v\nis truthy", a)
}
}
func (e *Expectation) ToSucceed() {
switch actual := e.actual.(type) {
case error:
if actual != nil {
e.fatalf("Expected error\n\t%v\nto have succeeded", actual)
}
default:
e.fatalf("Cannot check if non-error value\n\t%v\nsucceeded", actual)
}
}
func (e *Expectation) ToMatchError(expected interface{}) {
e.verifyExpectedNotNil(expected)
actual, ok := e.actual.(error)
if !ok {
e.fatalf("Cannot check if non-error value\n\t%v\nmatches error", e.actual)
}
switch expected := expected.(type) {
case error:
if !reflect.DeepEqual(actual, expected) {
e.fatalf("Expected\n\t%v\nto match error\n\t%v", actual, expected)
}
case string:
if actual.Error() != expected {
e.fatalf("Expected\n\t%v\nto match error\n\t%v", actual, expected)
}
default:
e.fatalf("Cannot match\n\t%v\nagainst non-error\n\t%v", actual, expected)
}
}
func (e *Expectation) ToContain(expected interface{}) {
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
switch actualKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", e.actual)
return
}
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
expectedValue = reflect.ValueOf([]interface{}{expected})
}
for i := 0; i < expectedValue.Len(); i++ {
var contained bool
expectedElem := expectedValue.Index(i).Interface()
for j := 0; j < actualValue.Len(); j++ {
if reflect.DeepEqual(actualValue.Index(j).Interface(), expectedElem) {
contained = true
break
}
}
if !contained {
e.fatalf("Expected\n\t%v\nto contain\n\t%v", e.actual, expectedElem)
return
}
}
}
func (e *Expectation) NotToContain(expected interface{}) {
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
switch actualKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", e.actual)
return
}
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
expectedValue = reflect.ValueOf([]interface{}{expected})
}
for i := 0; i < expectedValue.Len(); i++ {
expectedElem := expectedValue.Index(i).Interface()
for j := 0; j < actualValue.Len(); j++ {
if reflect.DeepEqual(actualValue.Index(j).Interface(), expectedElem) {
e.fatalf("Expected\n\t%v\nnot to contain\n\t%v", e.actual, expectedElem)
return
}
}
}
}
func (e *Expectation) ToMatchInAnyOrder(expected interface{}) {
expectedValue := reflect.ValueOf(expected)
expectedKind := expectedValue.Kind()
switch expectedKind {
case reflect.Array, reflect.Slice:
default:
e.fatalf("Expected\n\t%v\nto be an array", expected)
return
}
actualValue := reflect.ValueOf(e.actual)
actualKind := actualValue.Kind()
if actualKind != expectedKind {
e.fatalf("Expected\n\t%v\nto be the same type as\n\t%v", e.actual, expected)
return
}
if actualValue.Len() != expectedValue.Len() {
e.fatalf("Expected\n\t%v\nto have the same length as\n\t%v", e.actual, expected)
return
}
var unmatched []interface{}
for i := 0; i < expectedValue.Len(); i++ {
unmatched = append(unmatched, expectedValue.Index(i).Interface())
}
for i := 0; i < actualValue.Len(); i++ {
var found bool
for j, elem := range unmatched {
if reflect.DeepEqual(actualValue.Index(i).Interface(), elem) {
found = true
unmatched = append(unmatched[:j], unmatched[j+1:]...)
break
}
}
if !found {
e.fatalf("Expected\n\t%v\nto contain the same elements as\n\t%v", e.actual, expected)
}
}
}
func (e *Expectation) ToBeTemporally(matcher TemporalMatcher, compareTo interface{}) {
if actual, ok := e.actual.(time.Time); ok {
ct, ok := compareTo.(time.Time)
if !ok {
e.fatalf("Cannot compare to non-temporal value\n\t%v", compareTo)
return
}
switch matcher {
case Before:
if !actual.Before(ct) {
e.fatalf("Expected\n\t%v\nto be temporally before\n\t%v", e.actual, compareTo)
}
case BeforeOrSameTime:
if actual.After(ct) {
e.fatalf("Expected\n\t%v\nto be temporally before or at the same time as\n\t%v", e.actual, compareTo)
}
case After:
if !actual.After(ct) {
e.fatalf("Expected\n\t%v\nto be temporally after\n\t%v", e.actual, compareTo)
}
case AfterOrSameTime:
if actual.Before(ct) {
e.fatalf("Expected\n\t%v\nto be temporally after or at the same time as\n\t%v", e.actual, compareTo)
}
default:
e.fatalf("Cannot compare times with unexpected temporal matcher")
}
return
}
e.fatalf("Cannot compare non-temporal value\n\t%v", e.actual)
}
func (e *Expectation) verifyExpectedNotNil(expected interface{}) {
if expected == nil {
e.fatalf("Refusing to compare with <nil>. Use `ToBeNil` or `NotToBeNil` instead.")
}
}
func (e *Expectation) fatalf(format string, a ...any) {
// Prune the stack trace so that it's easier to see relevant lines
stack := strings.Split(string(debug.Stack()), "\n")
var prunedStack []string
for _, line := range stack {
if !stackTracePruneRE.MatchString(line) {
prunedStack = append(prunedStack, line)
}
}
msg := fmt.Sprintf(format, a...)
e.t.Fatalf("\n%s\n%s\n", strings.Join(prunedStack, "\n"), msg)
}

View File

@@ -1,28 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/expecter.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package matchers // import "go.opentelemetry.io/otel/sdk/internal/matchers"
import (
"testing"
)
type Expecter struct {
t *testing.T
}
func NewExpecter(t *testing.T) *Expecter {
return &Expecter{
t: t,
}
}
func (a *Expecter) Expect(actual interface{}) *Expectation {
return &Expectation{
t: a.t,
actual: actual,
}
}

View File

@@ -1,17 +0,0 @@
// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/matchers/temporal_matcher.go.tmpl
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package matchers // import "go.opentelemetry.io/otel/sdk/internal/matchers"
type TemporalMatcher byte
//nolint:revive // ignoring missing comments for unexported constants in an internal package
const (
Before TemporalMatcher = iota
BeforeOrSameTime
After
AfterOrSameTime
)

View File

@@ -11,14 +11,13 @@ import (
"testing"
"time"
"go.opentelemetry.io/otel/sdk/internal/matchers"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func basicTracerProvider(t *testing.T) *TracerProvider {
@@ -61,12 +60,10 @@ func (h *harness) testTracerProvider(subjectFactory func() trace.TracerProvider)
t.Run("allow creating an arbitrary number of TracerProvider instances", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
tp1 := subjectFactory()
tp2 := subjectFactory()
e.Expect(tp1).NotToEqual(tp2)
require.NotEqual(t, tp1, tp2)
})
t.Run("all methods are safe to be called concurrently", func(t *testing.T) {
t.Parallel()
@@ -88,7 +85,8 @@ func (h *harness) testTracerProvider(subjectFactory func() trace.TracerProvider)
return done
}
matchers.NewExpecter(t).Expect(func() {
require.NotPanics(t,
func() {
// Run with multiple TracerProvider to ensure they encapsulate
// their own Tracers.
tp1 := subjectFactory()
@@ -99,7 +97,7 @@ func (h *harness) testTracerProvider(subjectFactory func() trace.TracerProvider)
<-done1
<-done2
}).NotToPanic()
})
})
})
}
@@ -111,7 +109,6 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
t.Run("propagates the original context", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
ctxKey := testCtxKey{}
@@ -120,39 +117,35 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
ctx, _ = subject.Start(ctx, "test")
e.Expect(ctx.Value(ctxKey)).ToEqual(ctxValue)
require.Equal(t, ctx.Value(ctxKey), ctxValue)
})
t.Run("returns a span containing the expected properties", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
_, span := subject.Start(context.Background(), "test")
e.Expect(span).NotToBeNil()
e.Expect(span.SpanContext().IsValid()).ToBeTrue()
require.NotNil(t, span)
require.True(t, span.SpanContext().IsValid())
})
t.Run("stores the span on the provided context", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
ctx, span := subject.Start(context.Background(), "test")
e.Expect(span).NotToBeNil()
e.Expect(span.SpanContext()).NotToEqual(trace.SpanContext{})
e.Expect(trace.SpanFromContext(ctx)).ToEqual(span)
require.NotNil(t, span)
require.NotEqual(t, trace.SpanContext{}, span.SpanContext())
require.Equal(t, trace.SpanFromContext(ctx), span)
})
t.Run("starts spans with unique trace and span IDs", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
_, span1 := subject.Start(context.Background(), "span1")
@@ -161,14 +154,13 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
sc1 := span1.SpanContext()
sc2 := span2.SpanContext()
e.Expect(sc1.TraceID()).NotToEqual(sc2.TraceID())
e.Expect(sc1.SpanID()).NotToEqual(sc2.SpanID())
require.NotEqual(t, sc1.TraceID(), sc2.TraceID())
require.NotEqual(t, sc1.SpanID(), sc2.SpanID())
})
t.Run("propagates a parent's trace ID through the context", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
ctx, parent := subject.Start(context.Background(), "parent")
@@ -177,14 +169,13 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
psc := parent.SpanContext()
csc := child.SpanContext()
e.Expect(csc.TraceID()).ToEqual(psc.TraceID())
e.Expect(csc.SpanID()).NotToEqual(psc.SpanID())
require.Equal(t, csc.TraceID(), psc.TraceID())
require.NotEqual(t, csc.SpanID(), psc.SpanID())
})
t.Run("ignores parent's trace ID when new root is requested", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
ctx, parent := subject.Start(context.Background(), "parent")
@@ -193,14 +184,13 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
psc := parent.SpanContext()
csc := child.SpanContext()
e.Expect(csc.TraceID()).NotToEqual(psc.TraceID())
e.Expect(csc.SpanID()).NotToEqual(psc.SpanID())
require.NotEqual(t, csc.TraceID(), psc.TraceID())
require.NotEqual(t, csc.SpanID(), psc.SpanID())
})
t.Run("propagates remote parent's trace ID through the context", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
_, remoteParent := subject.Start(context.Background(), "remote parent")
@@ -210,14 +200,13 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
psc := remoteParent.SpanContext()
csc := child.SpanContext()
e.Expect(csc.TraceID()).ToEqual(psc.TraceID())
e.Expect(csc.SpanID()).NotToEqual(psc.SpanID())
require.Equal(t, csc.TraceID(), psc.TraceID())
require.NotEqual(t, csc.SpanID(), psc.SpanID())
})
t.Run("ignores remote parent's trace ID when new root is requested", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
subject := subjectFactory()
_, remoteParent := subject.Start(context.Background(), "remote parent")
@@ -227,14 +216,13 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
psc := remoteParent.SpanContext()
csc := child.SpanContext()
e.Expect(csc.TraceID()).NotToEqual(psc.TraceID())
e.Expect(csc.SpanID()).NotToEqual(psc.SpanID())
require.NotEqual(t, csc.TraceID(), psc.TraceID())
require.NotEqual(t, csc.SpanID(), psc.SpanID())
})
t.Run("all methods are safe to be called concurrently", func(t *testing.T) {
t.Parallel()
e := matchers.NewExpecter(t)
tracer := subjectFactory()
ctx, parent := tracer.Start(context.Background(), "span")
@@ -252,8 +240,8 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
psc := parent.SpanContext()
csc := child.SpanContext()
e.Expect(csc.TraceID()).ToEqual(psc.TraceID())
e.Expect(csc.SpanID()).NotToEqual(psc.SpanID())
require.Equal(t, csc.TraceID(), psc.TraceID())
require.NotEqual(t, csc.SpanID(), psc.SpanID())
}(fmt.Sprintf("span %d", i))
}
wg.Wait()
@@ -262,11 +250,11 @@ func (h *harness) testTracer(subjectFactory func() trace.Tracer) {
return done
}
e.Expect(func() {
require.NotPanics(t, func() {
done := runner(tracer)
<-done
}).NotToPanic()
})
})
})