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

Function TestValidateMetricName

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

Source from the content-addressed store, hash-verified

73}
74
75func TestValidateMetricName(t *testing.T) {
76 cfg := new(Limits)
77 cfg.EnforceMetricName = true
78
79 for _, c := range []struct {
80 metric model.Metric
81 expectErr error
82 reason string
83 }{
84 {map[model.LabelName]model.LabelValue{}, newNoMetricNameError(), missingMetricName},
85 {map[model.LabelName]model.LabelValue{model.MetricNameLabel: ""}, newInvalidMetricNameError(""), invalidMetricName},
86 {map[model.LabelName]model.LabelValue{model.MetricNameLabel: " "}, newInvalidMetricNameError(" "), invalidMetricName},
87 {map[model.LabelName]model.LabelValue{model.MetricNameLabel: "test.\xc5.metric"}, newInvalidMetricNameError("test.\xc5.metric"), invalidMetricName},
88 {map[model.LabelName]model.LabelValue{model.MetricNameLabel: "valid"}, nil, ""},
89 } {
90 err, reason := ValidateMetricName(cfg, cortexpb.FromMetricsToLabelAdapters(c.metric), model.LegacyValidation)
91 assert.Equal(t, c.expectErr, err)
92 if c.reason != "" {
93 assert.Equal(t, c.reason, reason)
94 } else {
95 assert.Empty(t, reason)
96 }
97 }
98
99 cfg.EnforceMetricName = false
100 err, reason := ValidateMetricName(cfg, cortexpb.FromMetricsToLabelAdapters(map[model.LabelName]model.LabelValue{}), model.LegacyValidation)
101 assert.Nil(t, err)
102 assert.Empty(t, reason)
103}
104
105func TestValidateLabels(t *testing.T) {
106 cfg := new(Limits)

Callers

nothing calls this directly

Calls 5

newNoMetricNameErrorFunction · 0.85
ValidateMetricNameFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected