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

Function TestLimitsLoadingFromJson

pkg/util/validation/limits_test.go:256–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

254}
255
256func TestLimitsLoadingFromJson(t *testing.T) {
257 SetDefaultLimitsForYAMLUnmarshalling(Limits{
258 MaxLabelNameLength: 100,
259 })
260
261 inp := `{"ingestion_rate": 0.5}`
262
263 l := Limits{}
264 err := json.Unmarshal([]byte(inp), &l)
265 require.NoError(t, err)
266
267 assert.Equal(t, 0.5, l.IngestionRate, "from json")
268 assert.Equal(t, 100, l.MaxLabelNameLength, "from defaults")
269
270 // Unmarshal should fail if input contains unknown struct fields and
271 // the decoder flag `json.Decoder.DisallowUnknownFields()` is set
272 inp = `{"unknown_fields": 100}`
273 l = Limits{}
274 dec := json.NewDecoder(strings.NewReader(inp))
275 dec.DisallowUnknownFields()
276 err = dec.Decode(&l)
277 assert.Error(t, err)
278}
279
280func TestLimitsTagsYamlMatchJson(t *testing.T) {
281 limits := reflect.TypeFor[Limits]()

Callers

nothing calls this directly

Calls 5

DecodeMethod · 0.95
EqualMethod · 0.65
UnmarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected