MCPcopy
hub / github.com/prometheus/client_golang / testDeletePartialMatch

Function testDeletePartialMatch

prometheus/vec_test.go:184–261  ·  prometheus/vec_test.go::testDeletePartialMatch
(t *testing.T, baseVec *GaugeVec)

Source from the content-addressed store, hash-verified

182}
183
184func testDeletePartialMatch(t *testing.T, baseVec *GaugeVec) {
185 assertNoMetric := func(t *testing.T) {
186 if n := len(baseVec.metrics); n != 0 {
187 t.Error("expected no metrics, got", n)
188 }
189 }
190
191 // No metric value is set.
192 if got, want := baseVec.DeletePartialMatch(Labels{"l1": "v1", "l2": "v2"}), 0; got != want {
193 t.Errorf("got %v, want %v", got, want)
194 }
195
196 baseVec.With(Labels{"l1": "baseValue1", "l2": "baseValue2", "l3": "baseValue3"}).Inc()
197 baseVec.With(Labels{"l1": "multiDeleteV1", "l2": "diff1BaseValue2", "l3": "v3"}).Set(42)
198 baseVec.With(Labels{"l1": "multiDeleteV1", "l2": "diff2BaseValue2", "l3": "v3"}).Set(84)
199 baseVec.With(Labels{"l1": "multiDeleteV1", "l2": "diff3BaseValue2", "l3": "v3"}).Set(168)
200
201 curriedVec := baseVec.MustCurryWith(Labels{"l2": "curriedValue2"})
202 curriedVec.WithLabelValues("curriedValue1", "curriedValue3").Inc()
203 curriedVec.WithLabelValues("curriedValue1", "differentCurriedValue3").Inc()
204 curriedVec.WithLabelValues("differentCurriedValue1", "differentCurriedValue3").Inc()
205
206 // Try to delete nonexistent label with existent value from curried vector.
207 if got, want := curriedVec.DeletePartialMatch(Labels{"lx": "curriedValue1"}), 0; got != want {
208 t.Errorf("got %v, want %v", got, want)
209 }
210
211 // Try to delete valid label with nonexistent value from curried vector.
212 if got, want := curriedVec.DeletePartialMatch(Labels{"l1": "badValue1"}), 0; got != want {
213 t.Errorf("got %v, want %v", got, want)
214 }
215
216 // Try to delete from a curried vector based on labels which were curried.
217 // This operation succeeds when run against the base vector below.
218 if got, want := curriedVec.DeletePartialMatch(Labels{"l2": "curriedValue2"}), 0; got != want {
219 t.Errorf("got %v, want %v", got, want)
220 }
221
222 // Try to delete from a curried vector based on labels which were curried,
223 // but the value actually exists in the base vector.
224 if got, want := curriedVec.DeletePartialMatch(Labels{"l2": "baseValue2"}), 0; got != want {
225 t.Errorf("got %v, want %v", got, want)
226 }
227
228 // Delete multiple matching metrics from a curried vector based on partial values.
229 if got, want := curriedVec.DeletePartialMatch(Labels{"l1": "curriedValue1"}), 2; got != want {
230 t.Errorf("got %v, want %v", got, want)
231 }
232
233 // Try to delete nonexistent label with existent value from base vector.
234 if got, want := baseVec.DeletePartialMatch(Labels{"lx": "curriedValue1"}), 0; got != want {
235 t.Errorf("got %v, want %v", got, want)
236 }
237
238 // Try to delete partially invalid labels from base vector.
239 if got, want := baseVec.DeletePartialMatch(Labels{"l1": "baseValue1", "l2": "badValue2"}), 0; got != want {
240 t.Errorf("got %v, want %v", got, want)
241 }

Callers 2

TestDeletePartialMatchFunction · 0.85

Calls 7

DeletePartialMatchMethod · 0.80
IncMethod · 0.65
WithMethod · 0.65
SetMethod · 0.65
MustCurryWithMethod · 0.65
WithLabelValuesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected