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

Function Test_ExemplarV2ToLabels

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

Source from the content-addressed store, hash-verified

8)
9
10func Test_ExemplarV2ToLabels(t *testing.T) {
11 symbols := []string{"", "foo", "bar"}
12 b := &labels.ScratchBuilder{}
13
14 tests := []struct {
15 desc string
16 e *ExemplarV2
17 isErr bool
18 expectedLabels labels.Labels
19 }{
20 {
21 desc: "Success",
22 e: &ExemplarV2{
23 LabelsRefs: []uint32{1, 2},
24 },
25 expectedLabels: labels.FromStrings("foo", "bar"),
26 },
27 {
28 desc: "Odd length of the label refs",
29 e: &ExemplarV2{
30 LabelsRefs: []uint32{1},
31 },
32 isErr: true,
33 },
34 {
35 desc: "Label name refs out of ranges",
36 e: &ExemplarV2{
37 LabelsRefs: []uint32{10, 2},
38 },
39 isErr: true,
40 },
41 {
42 desc: "Label value refs out of ranges",
43 e: &ExemplarV2{
44 LabelsRefs: []uint32{1, 10},
45 },
46 isErr: true,
47 },
48 }
49
50 for _, test := range tests {
51 t.Run(test.desc, func(t *testing.T) {
52 lbs, err := test.e.ToLabels(b, symbols)
53 if test.isErr {
54 require.Error(t, err)
55 } else {
56 require.Equal(t, test.expectedLabels.String(), lbs.String())
57 }
58 })
59 }
60}
61
62func Test_TimeSeriesV2ToLabels(t *testing.T) {
63 symbols := []string{"", "__name__", "test_metric", "job", "prometheus", "instance", "server-1"}

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