Skip to content

Commit baed670

Browse files
committed
Adapt tests
Signed-off-by: Quentin Devos <[email protected]>
1 parent f0be1c5 commit baed670

File tree

1 file changed

+51
-121
lines changed

1 file changed

+51
-121
lines changed

prometheus/vec_test.go

Lines changed: 51 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,17 @@ func TestDeleteWithCollisions(t *testing.T) {
4646
}
4747

4848
func TestDeleteWithConstraints(t *testing.T) {
49-
t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) {
50-
vec := NewConstrainedGaugeVec(
51-
GaugeOpts{
52-
Name: "test",
53-
Help: "helpless",
54-
},
55-
[]string{"l1", "l2"},
56-
ConstrainedLabels{
57-
"l2": func(s string) string { return "x" + s },
58-
},
59-
)
60-
testDelete(t, vec)
61-
})
62-
t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) {
63-
vec := NewConstrainedGaugeVec(
64-
GaugeOpts{
65-
Name: "test",
66-
Help: "helpless",
67-
},
68-
[]string{"l1"},
69-
ConstrainedLabels{
70-
"l2": func(s string) string { return "x" + s },
71-
},
72-
)
73-
testDelete(t, vec)
49+
vec := V2.NewGaugeVec(GaugeVecOpts{
50+
GaugeOpts{
51+
Name: "test",
52+
Help: "helpless",
53+
},
54+
ConstrainedLabels{
55+
{Name: "l1"},
56+
{Name: "l2", Constraint: func(s string) string { return "x" + s }},
57+
},
7458
})
59+
testDelete(t, vec)
7560
}
7661

7762
func testDelete(t *testing.T, vec *GaugeVec) {
@@ -129,32 +114,17 @@ func TestDeleteLabelValuesWithCollisions(t *testing.T) {
129114
}
130115

131116
func TestDeleteLabelValuesWithConstraints(t *testing.T) {
132-
t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) {
133-
vec := NewConstrainedGaugeVec(
134-
GaugeOpts{
135-
Name: "test",
136-
Help: "helpless",
137-
},
138-
[]string{"l1", "l2"},
139-
ConstrainedLabels{
140-
"l2": func(s string) string { return "x" + s },
141-
},
142-
)
143-
testDeleteLabelValues(t, vec)
144-
})
145-
t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) {
146-
vec := NewConstrainedGaugeVec(
147-
GaugeOpts{
148-
Name: "test",
149-
Help: "helpless",
150-
},
151-
[]string{"l1"},
152-
ConstrainedLabels{
153-
"l2": func(s string) string { return "x" + s },
154-
},
155-
)
156-
testDeleteLabelValues(t, vec)
117+
vec := V2.NewGaugeVec(GaugeVecOpts{
118+
GaugeOpts{
119+
Name: "test",
120+
Help: "helpless",
121+
},
122+
ConstrainedLabels{
123+
{Name: "l1"},
124+
{Name: "l2", Constraint: func(s string) string { return "x" + s }},
125+
},
157126
})
127+
testDeleteLabelValues(t, vec)
158128
}
159129

160130
func testDeleteLabelValues(t *testing.T, vec *GaugeVec) {
@@ -196,32 +166,18 @@ func TestDeletePartialMatch(t *testing.T) {
196166
}
197167

198168
func TestDeletePartialMatchWithConstraints(t *testing.T) {
199-
t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) {
200-
vec := NewConstrainedGaugeVec(
201-
GaugeOpts{
202-
Name: "test",
203-
Help: "helpless",
204-
},
205-
[]string{"l1", "l2", "l3"},
206-
ConstrainedLabels{
207-
"l2": func(s string) string { return "x" + s },
208-
},
209-
)
210-
testDeletePartialMatch(t, vec)
211-
})
212-
t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) {
213-
vec := NewConstrainedGaugeVec(
214-
GaugeOpts{
215-
Name: "test",
216-
Help: "helpless",
217-
},
218-
[]string{"l1", "l2"},
219-
ConstrainedLabels{
220-
"l3": func(s string) string { return "x" + s },
221-
},
222-
)
223-
testDeletePartialMatch(t, vec)
169+
vec := V2.NewGaugeVec(GaugeVecOpts{
170+
GaugeOpts{
171+
Name: "test",
172+
Help: "helpless",
173+
},
174+
ConstrainedLabels{
175+
{Name: "l1"},
176+
{Name: "l2", Constraint: func(s string) string { return "x" + s }},
177+
{Name: "l3"},
178+
},
224179
})
180+
testDeletePartialMatch(t, vec)
225181
}
226182

227183
func testDeletePartialMatch(t *testing.T, baseVec *GaugeVec) {
@@ -386,32 +342,17 @@ func testMetricVec(t *testing.T, vec *GaugeVec) {
386342

387343
func TestMetricVecWithConstraints(t *testing.T) {
388344
constraint := func(s string) string { return "x" + s }
389-
t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) {
390-
vec := NewConstrainedGaugeVec(
391-
GaugeOpts{
392-
Name: "test",
393-
Help: "helpless",
394-
},
395-
[]string{"l1", "l2"},
396-
ConstrainedLabels{
397-
"l2": constraint,
398-
},
399-
)
400-
testConstrainedMetricVec(t, vec, constraint)
401-
})
402-
t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) {
403-
vec := NewConstrainedGaugeVec(
404-
GaugeOpts{
405-
Name: "test",
406-
Help: "helpless",
407-
},
408-
[]string{"l1"},
409-
ConstrainedLabels{
410-
"l2": constraint,
411-
},
412-
)
413-
testConstrainedMetricVec(t, vec, constraint)
345+
vec := V2.NewGaugeVec(GaugeVecOpts{
346+
GaugeOpts{
347+
Name: "test",
348+
Help: "helpless",
349+
},
350+
ConstrainedLabels{
351+
{Name: "l1"},
352+
{Name: "l2", Constraint: constraint},
353+
},
414354
})
355+
testConstrainedMetricVec(t, vec, constraint)
415356
}
416357

417358
func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string) string) {
@@ -531,43 +472,32 @@ func TestCurryVecWithCollisions(t *testing.T) {
531472
func TestCurryVecWithConstraints(t *testing.T) {
532473
constraint := func(s string) string { return "x" + s }
533474
t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) {
534-
vec := NewConstrainedCounterVec(
475+
vec := V2.NewCounterVec(CounterVecOpts{
535476
CounterOpts{
536477
Name: "test",
537478
Help: "helpless",
538479
},
539-
[]string{"one", "two", "three"},
540480
ConstrainedLabels{
541-
"three": constraint,
481+
{Name: "one"},
482+
{Name: "two"},
483+
{Name: "three", Constraint: constraint},
542484
},
543-
)
544-
testCurryVec(t, vec)
545-
})
546-
t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) {
547-
vec := NewConstrainedCounterVec(
548-
CounterOpts{
549-
Name: "test",
550-
Help: "helpless",
551-
},
552-
[]string{"one", "two"},
553-
ConstrainedLabels{
554-
"three": constraint,
555-
},
556-
)
485+
})
557486
testCurryVec(t, vec)
558487
})
559488
t.Run("constrainedLabels reducing cardinality", func(t *testing.T) {
560489
constraint := func(s string) string { return "x" }
561-
vec := NewConstrainedCounterVec(
490+
vec := V2.NewCounterVec(CounterVecOpts{
562491
CounterOpts{
563492
Name: "test",
564493
Help: "helpless",
565494
},
566-
[]string{"one", "two", "three"},
567495
ConstrainedLabels{
568-
"three": constraint,
496+
{Name: "one"},
497+
{Name: "two"},
498+
{Name: "three", Constraint: constraint},
569499
},
570-
)
500+
})
571501
testConstrainedCurryVec(t, vec, constraint)
572502
})
573503
}

0 commit comments

Comments
 (0)