github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/util/marshal/labels_test.go (about) 1 package marshal 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/grafana/loki/pkg/loghttp" 8 ) 9 10 func TestNewLabelSet(t *testing.T) { 11 12 tests := []struct { 13 lbs string 14 want loghttp.LabelSet 15 wantErr bool 16 }{ 17 {`{1="foo"}`, nil, true}, 18 {`{_1="foo"}`, loghttp.LabelSet{"_1": "foo"}, false}, 19 } 20 for _, tt := range tests { 21 t.Run(tt.lbs, func(t *testing.T) { 22 got, err := NewLabelSet(tt.lbs) 23 if (err != nil) != tt.wantErr { 24 t.Errorf("NewLabelSet() error = %v, wantErr %v", err, tt.wantErr) 25 return 26 } 27 if !reflect.DeepEqual(got, tt.want) { 28 t.Errorf("NewLabelSet() = %v, want %v", got, tt.want) 29 } 30 }) 31 } 32 }