From baed6709f02ad9786867061d5606e9a31e8a196b Mon Sep 17 00:00:00 2001 From: Quentin Devos <4972091+Okhoshi@users.noreply.github.com> Date: Wed, 2 Nov 2022 11:12:03 +0100 Subject: [PATCH] Adapt tests Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com> --- prometheus/vec_test.go | 172 ++++++++++++----------------------------- 1 file changed, 51 insertions(+), 121 deletions(-) diff --git a/prometheus/vec_test.go b/prometheus/vec_test.go index 1b65c9fb2..63f52af23 100644 --- a/prometheus/vec_test.go +++ b/prometheus/vec_test.go @@ -46,32 +46,17 @@ func TestDeleteWithCollisions(t *testing.T) { } func TestDeleteWithConstraints(t *testing.T) { - t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1", "l2"}, - ConstrainedLabels{ - "l2": func(s string) string { return "x" + s }, - }, - ) - testDelete(t, vec) - }) - t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1"}, - ConstrainedLabels{ - "l2": func(s string) string { return "x" + s }, - }, - ) - testDelete(t, vec) + vec := V2.NewGaugeVec(GaugeVecOpts{ + GaugeOpts{ + Name: "test", + Help: "helpless", + }, + ConstrainedLabels{ + {Name: "l1"}, + {Name: "l2", Constraint: func(s string) string { return "x" + s }}, + }, }) + testDelete(t, vec) } func testDelete(t *testing.T, vec *GaugeVec) { @@ -129,32 +114,17 @@ func TestDeleteLabelValuesWithCollisions(t *testing.T) { } func TestDeleteLabelValuesWithConstraints(t *testing.T) { - t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1", "l2"}, - ConstrainedLabels{ - "l2": func(s string) string { return "x" + s }, - }, - ) - testDeleteLabelValues(t, vec) - }) - t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1"}, - ConstrainedLabels{ - "l2": func(s string) string { return "x" + s }, - }, - ) - testDeleteLabelValues(t, vec) + vec := V2.NewGaugeVec(GaugeVecOpts{ + GaugeOpts{ + Name: "test", + Help: "helpless", + }, + ConstrainedLabels{ + {Name: "l1"}, + {Name: "l2", Constraint: func(s string) string { return "x" + s }}, + }, }) + testDeleteLabelValues(t, vec) } func testDeleteLabelValues(t *testing.T, vec *GaugeVec) { @@ -196,32 +166,18 @@ func TestDeletePartialMatch(t *testing.T) { } func TestDeletePartialMatchWithConstraints(t *testing.T) { - t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1", "l2", "l3"}, - ConstrainedLabels{ - "l2": func(s string) string { return "x" + s }, - }, - ) - testDeletePartialMatch(t, vec) - }) - t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1", "l2"}, - ConstrainedLabels{ - "l3": func(s string) string { return "x" + s }, - }, - ) - testDeletePartialMatch(t, vec) + vec := V2.NewGaugeVec(GaugeVecOpts{ + GaugeOpts{ + Name: "test", + Help: "helpless", + }, + ConstrainedLabels{ + {Name: "l1"}, + {Name: "l2", Constraint: func(s string) string { return "x" + s }}, + {Name: "l3"}, + }, }) + testDeletePartialMatch(t, vec) } func testDeletePartialMatch(t *testing.T, baseVec *GaugeVec) { @@ -386,32 +342,17 @@ func testMetricVec(t *testing.T, vec *GaugeVec) { func TestMetricVecWithConstraints(t *testing.T) { constraint := func(s string) string { return "x" + s } - t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1", "l2"}, - ConstrainedLabels{ - "l2": constraint, - }, - ) - testConstrainedMetricVec(t, vec, constraint) - }) - t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) { - vec := NewConstrainedGaugeVec( - GaugeOpts{ - Name: "test", - Help: "helpless", - }, - []string{"l1"}, - ConstrainedLabels{ - "l2": constraint, - }, - ) - testConstrainedMetricVec(t, vec, constraint) + vec := V2.NewGaugeVec(GaugeVecOpts{ + GaugeOpts{ + Name: "test", + Help: "helpless", + }, + ConstrainedLabels{ + {Name: "l1"}, + {Name: "l2", Constraint: constraint}, + }, }) + testConstrainedMetricVec(t, vec, constraint) } func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string) string) { @@ -531,43 +472,32 @@ func TestCurryVecWithCollisions(t *testing.T) { func TestCurryVecWithConstraints(t *testing.T) { constraint := func(s string) string { return "x" + s } t.Run("constrainedLabels overlap variableLabels", func(t *testing.T) { - vec := NewConstrainedCounterVec( + vec := V2.NewCounterVec(CounterVecOpts{ CounterOpts{ Name: "test", Help: "helpless", }, - []string{"one", "two", "three"}, ConstrainedLabels{ - "three": constraint, + {Name: "one"}, + {Name: "two"}, + {Name: "three", Constraint: constraint}, }, - ) - testCurryVec(t, vec) - }) - t.Run("constrainedLabels are distinct from variableLabels", func(t *testing.T) { - vec := NewConstrainedCounterVec( - CounterOpts{ - Name: "test", - Help: "helpless", - }, - []string{"one", "two"}, - ConstrainedLabels{ - "three": constraint, - }, - ) + }) testCurryVec(t, vec) }) t.Run("constrainedLabels reducing cardinality", func(t *testing.T) { constraint := func(s string) string { return "x" } - vec := NewConstrainedCounterVec( + vec := V2.NewCounterVec(CounterVecOpts{ CounterOpts{ Name: "test", Help: "helpless", }, - []string{"one", "two", "three"}, ConstrainedLabels{ - "three": constraint, + {Name: "one"}, + {Name: "two"}, + {Name: "three", Constraint: constraint}, }, - ) + }) testConstrainedCurryVec(t, vec, constraint) }) }