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

Function TestValidateLabels_UTF8

pkg/util/validation/validate_test.go:25–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestValidateLabels_UTF8(t *testing.T) {
26 cfg := new(Limits)
27 userID := "testUser"
28
29 reg := prometheus.NewRegistry()
30 validateMetrics := NewValidateMetrics(reg)
31
32 cfg.MaxLabelValueLength = 25
33 cfg.MaxLabelNameLength = 25
34 cfg.MaxLabelNamesPerSeries = 2
35 cfg.MaxLabelsSizeBytes = 90
36 cfg.EnforceMetricName = true
37
38 tests := []struct {
39 description string
40 metric model.Metric
41 skipLabelNameValidation bool
42 expectedErr error
43 }{
44 {
45 description: "utf8 metric name",
46 metric: map[model.LabelName]model.LabelValue{model.MetricNameLabel: "test.utf8.metric"},
47 skipLabelNameValidation: false,
48 expectedErr: nil,
49 },
50 {
51 description: "invalid utf8 label name, but skipLabelNameValidation is true",
52 metric: map[model.LabelName]model.LabelValue{model.MetricNameLabel: "test.utf8.metric", "label1": "test.\xc5.label"},
53 skipLabelNameValidation: true,
54 expectedErr: nil,
55 },
56 {
57 description: "invalid utf8 label name, but skipLabelNameValidation is false",
58 metric: map[model.LabelName]model.LabelValue{model.MetricNameLabel: "test.utf8.metric", "test.\xc5.label": "value"},
59 skipLabelNameValidation: false,
60 expectedErr: newInvalidLabelError([]cortexpb.LabelAdapter{
61 {Name: model.MetricNameLabel, Value: "test.utf8.metric"},
62 {Name: "test.\xc5.label", Value: "value"},
63 }, "test.\xc5.label"),
64 },
65 }
66
67 for _, test := range tests {
68 t.Run(test.description, func(t *testing.T) {
69 err := ValidateLabels(validateMetrics, cfg, userID, cortexpb.FromMetricsToLabelAdapters(test.metric), test.skipLabelNameValidation, model.UTF8Validation)
70 assert.Equal(t, test.expectedErr, err, "wrong error")
71 })
72 }
73}
74
75func TestValidateMetricName(t *testing.T) {
76 cfg := new(Limits)

Callers

nothing calls this directly

Calls 6

NewValidateMetricsFunction · 0.85
newInvalidLabelErrorFunction · 0.85
ValidateLabelsFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected