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

Function TestCreateError

expfmt/text_create_test.go:726–788  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

724}
725
726func TestCreateError(t *testing.T) {
727 scenarios := []struct {
728 in *dto.MetricFamily
729 err string
730 }{
731 // 0: No metric.
732 {
733 in: &dto.MetricFamily{
734 Name: proto.String("name"),
735 Help: proto.String("doc string"),
736 Type: dto.MetricType_COUNTER.Enum(),
737 Metric: []*dto.Metric{},
738 },
739 err: "MetricFamily has no metrics",
740 },
741 // 1: No metric name.
742 {
743 in: &dto.MetricFamily{
744 Help: proto.String("doc string"),
745 Type: dto.MetricType_UNTYPED.Enum(),
746 Metric: []*dto.Metric{
747 {
748 Untyped: &dto.Untyped{
749 Value: proto.Float64(math.Inf(-1)),
750 },
751 },
752 },
753 },
754 err: "MetricFamily has no name",
755 },
756 // 2: Wrong type.
757 {
758 in: &dto.MetricFamily{
759 Name: proto.String("name"),
760 Help: proto.String("doc string"),
761 Type: dto.MetricType_COUNTER.Enum(),
762 Metric: []*dto.Metric{
763 {
764 Untyped: &dto.Untyped{
765 Value: proto.Float64(math.Inf(-1)),
766 },
767 },
768 },
769 },
770 err: "expected counter in metric",
771 },
772 }
773
774 for i, scenario := range scenarios {
775 var out bytes.Buffer
776 _, err := MetricFamilyToText(&out, scenario.in)
777 if err == nil {
778 t.Errorf("%d. expected error, got nil", i)
779 continue
780 }
781 if expected, got := scenario.err, err.Error(); strings.Index(got, expected) != 0 {
782 t.Errorf(
783 "%d. expected error starting with %q, got %q",

Callers

nothing calls this directly

Calls 3

MetricFamilyToTextFunction · 0.85
ErrorMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…