github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/context_test.go (about) 1 // (c) Copyright IBM Corp. 2021 2 // (c) Copyright Instana Inc. 2020 3 4 package instana_test 5 6 import ( 7 "context" 8 "testing" 9 10 instana "github.com/instana/go-sensor" 11 "github.com/stretchr/testify/assert" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestSpanFromContext_WithActiveSpan(t *testing.T) { 16 recorder := instana.NewTestRecorder() 17 tracer := instana.NewTracerWithEverything(&instana.Options{AgentClient: alwaysReadyClient{}}, recorder) 18 defer instana.ShutdownSensor() 19 20 span := tracer.StartSpan("test") 21 ctx := instana.ContextWithSpan(context.Background(), span) 22 23 sp, ok := instana.SpanFromContext(ctx) 24 require.True(t, ok) 25 assert.Equal(t, span, sp) 26 } 27 28 func TestSpanFromContext_NoActiveSpan(t *testing.T) { 29 _, ok := instana.SpanFromContext(context.Background()) 30 assert.False(t, ok) 31 }