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

Function testDiscriminatorHTTPHeader

expfmt/decode_test.go:371–419  ·  view source on GitHub ↗
(t testing.TB)

Source from the content-addressed store, hash-verified

369}
370
371func testDiscriminatorHTTPHeader(t testing.TB) {
372 scenarios := []struct {
373 input map[string]string
374 output Format
375 }{
376 {
377 input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="io.prometheus.client.MetricFamily"; encoding="delimited"`},
378 output: FmtProtoDelim,
379 },
380 {
381 input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="illegal"; encoding="delimited"`},
382 output: FmtUnknown,
383 },
384 {
385 input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="io.prometheus.client.MetricFamily"; encoding="illegal"`},
386 output: FmtUnknown,
387 },
388 {
389 input: map[string]string{"Content-Type": `text/plain; version=0.0.4`},
390 output: FmtText,
391 },
392 {
393 input: map[string]string{"Content-Type": `text/plain`},
394 output: FmtText,
395 },
396 {
397 input: map[string]string{"Content-Type": `text/plain; version=0.0.3`},
398 output: FmtUnknown,
399 },
400 }
401
402 for i, scenario := range scenarios {
403 var header http.Header
404
405 if len(scenario.input) > 0 {
406 header = http.Header{}
407 }
408
409 for key, value := range scenario.input {
410 header.Add(key, value)
411 }
412
413 actual := ResponseFormat(header)
414
415 if scenario.output != actual {
416 t.Errorf("%d. expected %s, got %s", i, scenario.output, actual)
417 }
418 }
419}
420
421func TestDiscriminatorHTTPHeader(t *testing.T) {
422 testDiscriminatorHTTPHeader(t)

Callers 2

Calls 2

ResponseFormatFunction · 0.85
AddMethod · 0.80

Tested by

no test coverage detected