github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/logql/log/util_test.go (about)

     1  package log
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func Test_sanitizeLabelKey(t *testing.T) {
    10  	tests := []struct {
    11  		key  string
    12  		want string
    13  	}{
    14  		{"  ", ""},
    15  		{"1", "_1"},
    16  		{"1 1 1", "_1_1_1"},
    17  		{"abc", "abc"},
    18  		{"$a$bc", "_a_bc"},
    19  		{"$a$bc", "_a_bc"},
    20  		{"   1 1 1  \t", "_1_1_1"},
    21  	}
    22  	for _, tt := range tests {
    23  		t.Run(tt.key, func(t *testing.T) {
    24  			if got := sanitizeLabelKey(tt.key, true); got != tt.want {
    25  				t.Errorf("sanitizeKey() = %v, want %v", got, tt.want)
    26  			}
    27  		})
    28  	}
    29  }
    30  
    31  func Test_UniqueStrings(t *testing.T) {
    32  	in := []string{"foo", "bar", "baz", "foo"}
    33  	out := uniqueString(in)
    34  	require.Equal(t, []string{"foo", "bar", "baz"}, out)
    35  	require.Equal(t, 4, cap(out))
    36  }