github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/pkg/reqid/request_id_test.go (about)

     1  package reqid
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestRequestID(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	reqID := New()
    14  
    15  	// Insert and extract request id
    16  	ctx := ToContext(context.Background(), reqID)
    17  	reqIDFromCtx := FromContext(ctx)
    18  	require.Equal(t, reqID, reqIDFromCtx)
    19  
    20  	// Extract from empty context
    21  	_ = FromContext(context.Background())
    22  }