MCPcopy Create free account
hub / github.com/prometheus/common / TestLabelNameIsValid

Function TestLabelNameIsValid

model/labels_test.go:93–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestLabelNameIsValid(t *testing.T) {
94 scenarios := []struct {
95 ln LabelName
96 valid bool
97 }{
98 {
99 ln: "Avalid_23name",
100 valid: true,
101 },
102 {
103 ln: "_Avalid_23name",
104 valid: true,
105 },
106 {
107 ln: "1valid_23name",
108 valid: false,
109 },
110 {
111 ln: "avalid_23name",
112 valid: true,
113 },
114 {
115 ln: "Ava:lid_23name",
116 valid: false,
117 },
118 {
119 ln: "a lid_23name",
120 valid: false,
121 },
122 {
123 ln: ":leading_colon",
124 valid: false,
125 },
126 {
127 ln: "colon:in:the:middle",
128 valid: false,
129 },
130 }
131
132 for _, s := range scenarios {
133 if s.ln.IsValid() != s.valid {
134 t.Errorf("Expected %v for %q using IsValid method", s.valid, s.ln)
135 }
136 if LabelNameRE.MatchString(string(s.ln)) != s.valid {
137 t.Errorf("Expected %v for %q using regexp match", s.valid, s.ln)
138 }
139 }
140}
141
142func TestSortLabelPairs(t *testing.T) {
143 labelPairs := LabelPairs{

Callers

nothing calls this directly

Calls 1

IsValidMethod · 0.45

Tested by

no test coverage detected