github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/log/context_test.go (about)

     1  package log
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestLevelFromContext(t *testing.T) {
    11  	for _, tt := range []struct {
    12  		ctx context.Context
    13  		lvl Level
    14  	}{
    15  		{
    16  			ctx: context.Background(),
    17  			lvl: TRACE,
    18  		},
    19  		{
    20  			ctx: WithLevel(context.Background(), INFO),
    21  			lvl: INFO,
    22  		},
    23  		{
    24  			ctx: WithLevel(WithLevel(context.Background(), ERROR), INFO),
    25  			lvl: INFO,
    26  		},
    27  	} {
    28  		t.Run("", func(t *testing.T) {
    29  			require.Equal(t, tt.lvl, LevelFromContext(tt.ctx))
    30  		})
    31  	}
    32  }
    33  
    34  func TestNamesFromContext(t *testing.T) {
    35  	for _, tt := range []struct {
    36  		ctx   context.Context
    37  		names []string
    38  	}{
    39  		{
    40  			ctx:   context.Background(),
    41  			names: []string{},
    42  		},
    43  		{
    44  			ctx:   WithNames(context.Background(), "a", "b"),
    45  			names: []string{"a", "b"},
    46  		},
    47  		{
    48  			ctx:   WithNames(WithNames(context.Background(), "a", "b"), "c", "d"),
    49  			names: []string{"a", "b", "c", "d"},
    50  		},
    51  	} {
    52  		t.Run("", func(t *testing.T) {
    53  			require.Equal(t, tt.names, NamesFromContext(tt.ctx))
    54  		})
    55  	}
    56  }