MCPcopy Create free account
hub / github.com/cortexproject/cortex / Test_TimeSeriesV2ToLabels

Function Test_TimeSeriesV2ToLabels

pkg/cortexpb/compatv2_test.go:62–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func Test_TimeSeriesV2ToLabels(t *testing.T) {
63 symbols := []string{"", "__name__", "test_metric", "job", "prometheus", "instance", "server-1"}
64 b := &labels.ScratchBuilder{}
65
66 tests := []struct {
67 desc string
68 ts *TimeSeriesV2
69 isErr bool
70 expectedLabels labels.Labels
71 }{
72 {
73 desc: "Success",
74 ts: &TimeSeriesV2{
75 LabelsRefs: []uint32{1, 2, 3, 4, 5, 6},
76 },
77 expectedLabels: labels.FromStrings("__name__", "test_metric", "job", "prometheus", "instance", "server-1"),
78 },
79 {
80 desc: "Odd length of the label refs",
81 ts: &TimeSeriesV2{
82 LabelsRefs: []uint32{1, 2, 3},
83 },
84 isErr: true,
85 },
86 {
87 desc: "Label name refs out of ranges",
88 ts: &TimeSeriesV2{
89 LabelsRefs: []uint32{1, 2, 10, 4},
90 },
91 isErr: true,
92 },
93 {
94 desc: "Label value refs out of ranges",
95 ts: &TimeSeriesV2{
96 LabelsRefs: []uint32{1, 2, 3, 10},
97 },
98 isErr: true,
99 },
100 }
101
102 for _, test := range tests {
103 t.Run(test.desc, func(t *testing.T) {
104 lbs, err := test.ts.ToLabels(b, symbols)
105 if test.isErr {
106 require.Error(t, err)
107 } else {
108 require.Equal(t, test.expectedLabels.String(), lbs.String())
109 }
110 })
111 }
112}

Callers

nothing calls this directly

Calls 5

RunMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ToLabelsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected