(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func TestShouldMemoize(t *testing.T) { |
| 159 | tcs := []struct { |
| 160 | regex string |
| 161 | shouldMemoize bool |
| 162 | }{ |
| 163 | { |
| 164 | regex: ".*", |
| 165 | shouldMemoize: false, |
| 166 | }, |
| 167 | { |
| 168 | regex: "foo.*", |
| 169 | shouldMemoize: false, |
| 170 | }, |
| 171 | { |
| 172 | regex: ".*bar", |
| 173 | shouldMemoize: false, |
| 174 | }, |
| 175 | { |
| 176 | regex: "foo|bar", |
| 177 | shouldMemoize: false, |
| 178 | }, |
| 179 | { |
| 180 | regex: ".*bar.*", // creates a containsStringMatcher so should not memoize |
| 181 | shouldMemoize: false, |
| 182 | }, |
| 183 | { |
| 184 | regex: ".*bar.*foo.*", // now uses a stringMatcher in prometheus v0.311.2+ |
| 185 | shouldMemoize: false, |
| 186 | }, |
| 187 | } |
| 188 | |
| 189 | for _, tc := range tcs { |
| 190 | t.Run(tc.regex, func(t *testing.T) { |
| 191 | m, err := labels.NewFastRegexMatcher(tc.regex) |
| 192 | require.NoError(t, err) |
| 193 | require.Equal(t, tc.shouldMemoize, shouldMemoize(m)) |
| 194 | }) |
| 195 | } |
| 196 | } |
nothing calls this directly
no test coverage detected