github.com/mier85/go-sensor@v1.30.1-0.20220920111756-9bf41b3bc7e0/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  	"github.com/instana/testify/assert"
    11  	"github.com/instana/testify/require"
    12  	instana "github.com/mier85/go-sensor"
    13  )
    14  
    15  func TestSpanFromContext_WithActiveSpan(t *testing.T) {
    16  	recorder := instana.NewTestRecorder()
    17  	tracer := instana.NewTracerWithEverything(&instana.Options{}, recorder)
    18  
    19  	span := tracer.StartSpan("test")
    20  	ctx := instana.ContextWithSpan(context.Background(), span)
    21  
    22  	sp, ok := instana.SpanFromContext(ctx)
    23  	require.True(t, ok)
    24  	assert.Equal(t, span, sp)
    25  }
    26  
    27  func TestSpanFromContext_NoActiveSpan(t *testing.T) {
    28  	_, ok := instana.SpanFromContext(context.Background())
    29  	assert.False(t, ok)
    30  }