MCPcopy
hub / github.com/grafana/dskit / TestLimitsMap_UnmarshalYAML

Function TestLimitsMap_UnmarshalYAML

flagext/map_test.go:160–259  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func TestLimitsMap_UnmarshalYAML(t *testing.T) {
161 t.Run("numeric", func(t *testing.T) {
162 tc := []struct {
163 name string
164 input string
165 expected map[string]float64
166 error string
167 }{
168 {
169 name: "unmarshal without error",
170 input: `
171key1: 10
172key2: 20
173`,
174 expected: map[string]float64{"key1": 10, "key2": 20},
175 },
176 {
177 name: "unmarshal with validation error",
178 input: `
179key1: -10
180key2: 20
181`,
182 error: "value cannot be negative",
183 },
184 {
185 name: "unmarshal with parsing error",
186 input: `
187key1: 10
188key2: 20
189 key3: 30
190`,
191 error: "yaml: line 3: found a tab character that violates indentation",
192 },
193 }
194
195 for _, tt := range tc {
196 t.Run(tt.name, func(t *testing.T) {
197 lm := NewLimitsMap(fakeFloat64Validator)
198 err := yaml.Unmarshal([]byte(tt.input), &lm)
199 if tt.error != "" {
200 require.Error(t, err)
201 require.Equal(t, tt.error, err.Error())
202 } else {
203 require.NoError(t, err)
204 require.Equal(t, tt.expected, lm.data)
205 }
206 })
207 }
208 })
209
210 t.Run("string", func(t *testing.T) {
211 tc := []struct {
212 name string
213 input string
214 expected map[string]string
215 error string
216 }{
217 {

Callers

nothing calls this directly

Calls 5

NewLimitsMapFunction · 0.85
RunMethod · 0.80
UnmarshalMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected