Skip to content

Commit

Permalink
Adapt tests
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
  • Loading branch information
Okhoshi committed Nov 7, 2022
1 parent f0be1c5 commit baed670
Showing 1 changed file with 51 additions and 121 deletions.
172 changes: 51 additions & 121 deletions prometheus/vec_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit baed670

Please sign in to comment.