MCPcopy Index your code
hub / github.com/prometheus/prometheus / TestPromNullByteHandling

Function TestPromNullByteHandling

model/textparse/promparse_test.go:573–630  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

571}
572
573func TestPromNullByteHandling(t *testing.T) {
574 cases := []struct {
575 input string
576 err string
577 }{
578 {
579 input: "null_byte_metric{a=\"abc\x00\"} 1",
580 err: "",
581 },
582 {
583 input: "a{b=\"\x00ss\"} 1\n",
584 err: "",
585 },
586 {
587 input: "a{b=\"\x00\"} 1\n",
588 err: "",
589 },
590 {
591 input: "a{b=\"\x00\"} 1\n",
592 err: "",
593 },
594 {
595 input: "a{b=\x00\"ssss\"} 1\n",
596 err: "expected label value, got \"\\x00\" (\"INVALID\") while parsing: \"a{b=\\x00\"",
597 },
598 {
599 input: "a{b=\"\x00",
600 err: "expected label value, got \"\\\"\\x00\\n\" (\"INVALID\") while parsing: \"a{b=\\\"\\x00\\n\"",
601 },
602 {
603 input: "a{b\x00=\"hiih\"} 1",
604 err: "expected equal, got \"\\x00\" (\"INVALID\") while parsing: \"a{b\\x00\"",
605 },
606 {
607 input: "a\x00{b=\"ddd\"} 1",
608 err: "expected value after metric, got \"\\x00\" (\"INVALID\") while parsing: \"a\\x00\"",
609 },
610 {
611 input: "a 0 1\x00",
612 err: "expected next entry after timestamp, got \"\\x00\" (\"INVALID\") while parsing: \"a 0 1\\x00\"",
613 },
614 }
615
616 for i, c := range cases {
617 p := NewPromParser([]byte(c.input), labels.NewSymbolTable(), false)
618 var err error
619 for err == nil {
620 _, err = p.Next()
621 }
622
623 if c.err == "" {
624 require.Equal(t, io.EOF, err, "test %d", i)
625 continue
626 }
627
628 require.EqualError(t, err, c.err, "test %d", i)
629 }
630}

Callers

nothing calls this directly

Calls 3

NextMethod · 0.95
NewSymbolTableFunction · 0.92
NewPromParserFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…